=============================================================================== Example 1 - Arithemtic Comparisions - intro1 ------------------------------------------------------------------------------- #!/bin/bash num0=10 num1=10 num2=10 num3=30 num4=40 if [ $num1 -eq $num2 ] then echo $num1 is the same as $num2 fi if [ $num3 -gt $num2 ] then echo $num3 is greater than $num2 fi if [ $num3 -lt $num4 ] then echo $num3 is less than $num4 fi if [ $num1 -ne $num4 ] then echo $num1 is not equal to $num4 fi if [ $num0 -le $num1 ] then echo $num0 is less than or equal to $num1 fi if [ $num1 -ge $num0 ] then echo $num1 is greater than or equal to $num0 fi =============================================================================== Example 2 - String comparisons - intro2 ------------------------------------------------------------------------------- #!/bin/bash # Please see 1. and 2. below (for more information) # 1 http://www.ibm.com/developerworks/opensource/library/l-bash-test/index.html # 2. http://tldp.org/LDP/abs/html/refcards.html # 3. http://tldp.org/LDP/abs/html/comparison-ops.html#SCOMPARISON1 string1=abc string2=abc string3=abcd string4=abcde if [ $string1 = $string2 ] then echo $string1 is equal to $string2 fi if [ $string1 != $string3 ] then echo $string1 is NOT equal to $string3 fi if [ $string2 \< $string3 ] then echo $string2 is less than $string3 fi if [ $string3 \> $string2 ] then echo $string3 is greater than $string2 fi if [ $string1 \< $string4 ] || [ $string1 = $string4 ] then echo $string1 is less than or equal to $string4 fi if [ $string4 \> $string1 ] || [ $string4 = $string1 ] then echo $string4 is greater than or equal to $string1 fi =============================================================================== Example 3 - Other Examples - intro3 ------------------------------------------------------------------------------- #!/bin/bash # Reference: http://www.ibm.com/developerworks/opensource/library/l-bash-test/index.html [ "abc" != "def" ];echo $? [ "abc" != "abc" ];echo $? test -d "$HOME" ;echo $? [ -d "$HOME" ];echo $? [ -d /bin ];echo $? [ -d /binny ];echo $? test 3 -gt 4 && echo True || echo false =============================================================================== Example 4 - Other examples - intro3 ------------------------------------------------------------------------------- #!/bin/bash # Reference: http://www.ibm.com/developerworks/opensource/library/l-bash-test/index.html if test -d "$HOME" then echo directory $HOME present else echo direcotry $HOME present fi if test -d /bin then echo directory /bin present else echo direcotry /bin not present fi if test -d /binny then echo directory /binny present else echo direcotry /binny not present fi