| 1 | #!/bin/sh
|
| 2 |
|
| 3 | # The previous if-conditionals were string comparisons. We will now take
|
| 4 | # a look into using number comparisons.
|
| 5 | #
|
| 6 | # -eq # equal to
|
| 7 | # -ne # not equal to
|
| 8 | # -gt # greater than
|
| 9 | # -ge # greater than or equal to
|
| 10 | # -lt # less than
|
| 11 | # -le # less than or equal to
|
| 12 | #
|
| 13 | # Also, when you input a number from the 'read' command, it
|
| 14 | # automatically becomes a integer. Shell cannot use float or doubles.
|
| 15 | # To use decimal numbers, you must delegate it to other tools that will
|
| 16 | # be taught much later
|
| 17 | #
|
| 18 | # $ read user_input
|
| 19 | # $ if [ $1 -eq 1412 ]; then
|
| 20 | # $ echo "Correct pin"
|
| 21 | # $ fi
|
| 22 | #
|
| 23 | # You can also do operations but these must be surrounded by double
|
| 24 | # parenthesis.
|
| 25 | #
|
| 26 | # $ $((10 + 2)) # 12 addition
|
| 27 | # $ $((10 - 2)) # 8 subtraction
|
| 28 | # $ $((10 * 2)) # 20 multiplication
|
| 29 | # $ $((10 / 2)) # 5 division
|
| 30 | # $ $((-10 % 3)) # -1 modulo, finds out the remainder
|
| 31 | #
|
| 32 | # Write a script that tells you if an inputted number is even or odd.
|
| 33 |
|
| 34 | num=$1
|
| 35 |
|
| 36 | echo "odd"
|
| 37 | echo "even"
|