Comparison operators for strings
The comparison for strings are different than for numbers. Here is a partial list:
Operator |
Explanation |
---|---|
|
This stands for equal to |
|
This stands for not equal to |
|
This stands for greater than |
|
This stands for less than |
Now let's take a look at Script 3:
Chapter 2 - Script 3
1 #!/bin/sh 2 # 3 # 6/13/2017 4 # 5 echo "script3" 6 7 # String variables 8 str1="Kirk" 9 str2="Kirk" 10 str3="Spock" 11 str3="Dr. McCoy" 12 str4="Engineer Scott" 13 str5="A" 14 str6="B" 15 16 echo str1=$str1 str2=$str2 str3=$str3 str4=$str4 17 18 if [ "$str1" = "$str2" ] ; then 19 echo str1 equals str2 20 else 21 echo str1 does not equal str2 22 fi 23 24 if [ "$str1" != "$str2" ] ; then 25 echo str1 does not equal str2 26 else 27 echo str1 equals str2 28 fi 29 30...