Besides if and else statements, Bash offers case or switch statements and loop constructs that can be used to simplify logic so that it is more readable and sustainable. Imagine creating an if statement with many elif evaluations. It would become cumbersome!
#!/bin/bash VAR=10
# Multiple IF statements if [ $VAR -eq 1 ]; then echo "$VAR" elif [ $VAR -eq 2]; then echo "$VAR" elif [ $VAR -eq 3]; then echo "$VAR" # .... to 10 else echo "I am not looking to match this value" fi
In a large number of blocks of conditional logic of if and elifs, each if and elif needs to be evaluated before executing a specific branch of code. It can be faster to use a case/switch statement, because the first match will be executed (and it looks prettier).