Conditionals
if/then/else/fi ek conditional banate hain, aur [ ... ] — har token ke around spaces zaroori hain — actually test command ki call hai, koi special syntax nahi. -eq numbers compare karta hai; string comparisons ke liye = use hota hai.
[[ ... ]] Bash ki apni, zyada modern conditional syntax hai — yeh brackets ke andar directly && aur || support karta hai, aur [ ] jitni defensively variables ko quote karne ki zaroorat nahi padti.
script.sh
Khud try karo →x=5 if [[ $x -eq 5 && $x -lt 10 ]]; then echo "x is five and less than ten" fi
Output
x is five and less than ten
Aage: loops — for aur while, kisi list ya range par iterate karna.
Practice exercise
score=85 diya gaya hai, [ ] use karke agar score 60 ya usse zyada ho to "pass" print karo, warna "fail" print karo.