LDP/LDP/guide/docbook/abs-guide/ex13.sh

37 lines
667 B
Bash
Raw Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
a=4
b=5
2001-10-15 14:21:41 +00:00
# Here "a" and "b" can be treated either as integers or strings.
# There is some blurring between the arithmetic and string comparisons,
#+ since Bash variables are not strongly typed.
# Bash permits integer operations and comparisons on variables
#+ whose value consists of all-integer characters.
2005-03-21 13:51:11 +00:00
# Caution advised, however.
2001-07-10 14:25:50 +00:00
2002-07-22 15:11:51 +00:00
echo
2001-07-10 14:25:50 +00:00
if [ "$a" -ne "$b" ]
then
echo "$a is not equal to $b"
echo "(arithmetic comparison)"
fi
echo
if [ "$a" != "$b" ]
then
echo "$a is not equal to $b."
echo "(string comparison)"
2002-07-22 15:11:51 +00:00
# "4" != "5"
# ASCII 52 != ASCII 53
2001-07-10 14:25:50 +00:00
fi
2002-07-22 15:11:51 +00:00
# In this particular instance, both "-ne" and "!=" work.
2001-09-04 13:27:31 +00:00
2001-07-10 14:25:50 +00:00
echo
exit 0