AnyCompiler

Conditionals

if/then/else/fi ek conditional banate hain, aur [ ... ] — har token ke around spaces zaroori hain — waqai test command ki call hai, koi special syntax nahi. -eq numbers compare karta hai; string comparisons ke liye = use hota hai.

x=5
if [ "$x" -eq 5 ]; then
  echo "x is five"
fi
Output
x is five

[[ ... ]] 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 parti.

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 kar ke agar score 60 ya us se zyada ho to "pass" print karein, warna "fail" print karein.