Decision-making is the act of performing different actions based on different conditions.
The following are the two types of decision-making statements we can use in Unix/Linux shell:
Comparison | Interpretation |
---|---|
$x -eq $y | $x is equal to $y |
$x -ne $y | $x is not equal to $y |
$x -lt $y | $x < $y |
$x -gt $y | $x > $y |
$x -le $y | $x <= $y |
$x -ge $y | $x >= $y |
Logical operators are used to combine different binary operators.
The codes below explain the usage of both decision-making methods.
score=73if [ "$score" -ge 90 ]; thenecho "A*"elif [ "$score" -ge 80 ]; thenecho "A"elif [ "$score" -ge 70 ]; thenecho "B"elif [ "$score" -ge 60 ]; thenecho "C"elif [ "$score" -ge 50 ]; thenecho "D"elseecho "F"fi
temp="Algorithms"case "$temp" in"Databases") echo "Databases are simply magical!";;"Operating Systems") echo "Operating Systems are awesome :)";;"Algorithms") echo "I love Algorithms <3";;esac
Free Resources