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=73 if [ "$score" -ge 90 ]; then echo "A*" elif [ "$score" -ge 80 ]; then echo "A" elif [ "$score" -ge 70 ]; then echo "B" elif [ "$score" -ge 60 ]; then echo "C" elif [ "$score" -ge 50 ]; then echo "D" else echo "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
RELATED TAGS
CONTRIBUTOR
View all Courses