AnyCompiler

Quoting

Single quotes aur double quotes Bash mein differently behave karte hain, jo zyada tar dusri languages se aane walon ko confuse kar deta hai. Single quotes ke andar, sab kuch completely literal hota hai — koi variable expansion bilkul nahi hoti. Double quotes ke andar, $name phir bhi uski value mein expand ho jaata hai.

name="world"
echo 'Hello, $name!'
echo "Hello, $name!"
Output
Hello, $name!
Hello, world!

Command substitution

$(command) command ko run karta hai aur usska printed output wahin, text ki tarah substitute kar deta hai — isi tarah aap ek command ka result capture karke dusri ke andar use karte ho, kyunki kisi arbitrary command se directly "return value" lene ka koi aur tareeka nahi hai.

greeting=$(echo "Hello")
echo "$greeting, Bash!"
Output
Hello, Bash!

Aage: exit codes — woh number jisse har ek command finish hoti hai, aur usey kaise check karte hain.

Practice exercise

word="Bash" diya gaya hai, single quotes use karke "$word is literal" print karo taaki $word expand na ho, phir double quotes use karke "$word is expanded" print karo taaki woh expand ho jaaye.