|
96 | 96 | fi |
97 | 97 | ``` |
98 | 98 |
|
| 99 | +If you have multiple conditions and scenerios, then can use `elif` statement with `if` and `else` statements. |
| 100 | + |
| 101 | +```bash |
| 102 | +#!/bin/bash |
| 103 | + |
| 104 | +read -p "Enter a number: " num |
| 105 | + |
| 106 | +if [[ $num -gt 0 ]] ; then |
| 107 | + echo "The number is positive" |
| 108 | +elif [[ $num -lt 0 ]] ; then |
| 109 | + echo "The number is negative" |
| 110 | +else |
| 111 | + echo "The number is 0" |
| 112 | +fi |
| 113 | +``` |
| 114 | + |
99 | 115 | ## Switch case statements |
100 | 116 |
|
101 | 117 | As in other programming languages, you can use a `case` statement to simplify complex conditionals when there are multiple different choices. So rather than using a few `if`, and `if-else` statements, you could use a single `case` statement. |
|
0 commit comments