Concept Flow - if-then-fi structure
Start
Evaluate condition
Execute commands inside then
End if
Skip commands inside then
End if
The script checks a condition. If true, it runs commands inside then. If false, it skips them and ends the if block.
if [ "$num" -gt 0 ]; then echo "Positive number" fi
| Step | Condition | Result | Branch Taken | Output |
|---|---|---|---|---|
| 1 | [ "$num" -gt 0 ] | True | Execute then block | Positive number |
| 2 | End of if | - | Exit if | - |
| Variable | Start | After Step 1 | Final |
|---|---|---|---|
| num | 5 | 5 | 5 |
if-then-fi structure in bash: if [ condition ]; then commands fi - Checks condition - Runs commands if true - Ends with fi - Skips commands if false