Decision Making
Control script flow based on conditions.
Shell Script · Conditional Statements
Shell Scripting · Lesson 8
Use if else conditions in shell scripting. Compare numbers and strings. Test command and operators. Build decision making logic like real projects.
Conditional statements allow a script to make decisions based on conditions. Different blocks of code execute depending on whether a condition is true or false.
In shell scripting, conditions are commonly written usingif,elif, andelse.
Control script flow based on conditions.
Scripts respond dynamically to user input and data.
Handle success and failure conditions properly.
| Operator | Meaning |
|---|---|
| -eq | Equal to |
| -ne | Not equal to |
| -gt | Greater than |
| -lt | Less than |
| -ge | Greater than or equal to |
| -le | Less than or equal to |
| Operator | Meaning |
|---|---|
| = | Strings are equal |
| != | Strings are not equal |
| -z | String is empty |
| -n | String is not empty |
| Operator | Meaning |
|---|---|
| -f | Check if file exists |
| -d | Check if directory exists |
| -r | Check read permission |
| -w | Check write permission |
| -x | Check execute permission |
Executes a block of code only if the condition is true.
Executes one block if condition is true, otherwise another.
Used when checking multiple conditions.
Compare strings using = or != operators.
Check whether a file exists.
Next lesson: Loops (for, while, until)