| 1 | #!/bin/bash |
| 2 | |
| 3 | a=4 |
| 4 | b=5 |
| 5 | |
| 6 | # Here "a" and "b" can be treated either as integers or strings. |
| 7 | # There is some blurring between the arithmetic and string comparisons, |
| 8 | #+ since Bash variables are not strongly typed. |
| 9 | |
| 10 | # Bash permits integer operations and comparisons on variables |
| 11 | #+ whose value consists of all-integer characters. |
| 12 | # Caution advised, however. |
| 13 | |
| 14 | echo |
| 15 | |
| 16 | if [ "$a" -ne "$b" ] |
| 17 | then |
| 18 | echo "$a is not equal to $b" |
| 19 | echo "(arithmetic comparison)" |
| 20 | fi |
| 21 | |
| 22 | echo |
| 23 | |
| 24 | if [ "$a" != "$b" ] |
| 25 | then |
| 26 | echo "$a is not equal to $b." |
| 27 | echo "(string comparison)" |
| 28 | # "4" != "5" |
| 29 | # ASCII 52 != ASCII 53 |
| 30 | fi |
| 31 | |
| 32 | # In this particular instance, both "-ne" and "!=" work. |
| 33 | |
| 34 | echo |
| 35 | |
| 36 | exit 0 |