← Shell Scripting (Bash) learning pathShell Scripting (Bash) · Module 7 of 10
Conditions and loops
Make decisions and repeat tasks in scripts.
📖 Key ideas
- if [[ $age -ge 18 ]]; then ...; elif ...; else ...; fi.
- File tests: -f file exists, -d directory exists.
- String compare: [[ $a == "yes" ]]; numbers: -eq, -lt, -gt.
- for f in *.txt; do echo "$f"; done.
- 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