Concept Flow - Why conditionals branch script logic
Start script
Evaluate condition
Run True
Continue script
End
The script starts by checking a condition. If true, it runs one set of commands; if false, it runs another. Then it continues.
if [ "$age" -ge 18 ]; then echo "Adult" else echo "Minor" fi
| Step | Condition | Result | Branch Taken | Output |
|---|---|---|---|---|
| 1 | [ "$age" -ge 18 ] | True | Then branch | Adult |
| 2 | End of if | - | - | - |
| Variable | Start | After Step 1 | Final |
|---|---|---|---|
| age | 20 | 20 | 20 |
if [ condition ]; then # commands if true else # commands if false fi - Condition decides which commands run - Only one branch runs per check - Helps script choose actions based on data