← Shell Scripting (Bash) learning path
Shell Scripting (Bash) · Module 7 of 10

Conditions and loops

Make decisions and repeat tasks in scripts.

📖 Key ideas

  1. if [[ $age -ge 18 ]]; then ...; elif ...; else ...; fi.
  2. File tests: -f file exists, -d directory exists.
  3. String compare: [[ $a == "yes" ]]; numbers: -eq, -lt, -gt.
  4. for f in *.txt; do echo "$f"; done.
  5. while read -r line; do ...; done < file.
💡 Real-life example: Loops are a factory machine stamping every item on the belt with the same action.
[[ ]]Bash test expression
-eqNumeric equal
-fTests if a file exists
for ... doneLoop syntax