Conditional statements help you to execute parts of a shell script only if
certain conditions hold. Below, we give the syntax and examples for three
common variants of if statements as well as the case statement which acts
like switch statements in other languages.
Here, expression often takes the form of comparing strings using operators == or != or comparing numbers using operators -eq (equal), -ne (not equal), -lt (less than), -gt (greater than), or -ge (greater than or equal to).
However, there are other conditional expressions, many related to files (for example -e test.txt returns true if the file test.txt exists). For a full listing, see this manual page.
#!/bin/shif[$1-eq$2]thenecho"$1 is equal to $2"elif[$1-gt$2]thenecho"$1 is greater than $2"elif[$1-lt$2]thenecho"$1 is less than $2"elseecho"None of the condition met"fi
#!/bin/shread-p"Enter a number between 1 and 3 inclusive > "character
case$characterin1)echo"You entered one.";;2)echo"You entered two.";;3)echo"You entered three.";;*)echo"You did not enter a number between 1 and 3."esac