Syntax. (Programming languages should not care about whitespace. I should be able to type [$neko="hi"], but unfortunately that doesn’t work.)
if [ $neko = "hi" ] && [ $kami = "there" ]; then
# do stuff
elif [ $neko = "hi there" ]; then
# do other stuff
fi
Greater than and less than for strings:
[ "$var1" \< "$var2" ] # true if var1 < var2
[ "$var1" \> "$var2" ] #true if var1 > var2
*Note: the quotes are needed around the variables if they have multiple words in them (that is, if there’s spaces). Seriously…wtf? ><
Integer comparisons (this page goes into detail on many different comparison operators for both strings and integers; I’ve copied most of them into here, in case it happens to disappear for whatever reason..):
[ num1 -eq num2 ] # true if num1 == num2
[ num1 -ne num2 ] # true if num1 != num2
[ num1 -lt num2 ] # true if num1 < num2
[ num1 -gt num2 ] # true if num1 > num2
[ num1 -le num2 ] # true if num1 <= num2
[ num1 -ge num2 ] # true if num1 >= num2
String comparisons:
[ str1 = str2 ] # true if str1 == str2
# Note: [ str1=str2] assigns str2 to str1, I think.
[ str1 != str2 ] # true if str1 != str2
[ -n str1 ] # true if str1 is not null (length > 0)
[ -z str1 ] # true if str1 is null (length == 0)
File comparisons:
[ -f filename ] # true if the file exists & is a normal file
[ -d filename ]# true if the file exists & is a directory
[ -s filename ] # true if file is not empty
[ -r filename ] # true if file is readable
[ -w filename ] # true if file is writeable
[ -x filename ] # true if file is executable
Multiple conditions:
[ cond1 -a cond2 ] # true if cond1 && cond2 is true
[ cond1 -o cond2 ] # true if cond1 | cond2 is true
[ ! cond1 ] # true if cond1 is false