1. Logical operators;
Logical operator Instances:
A=Tenb= -if[$a! =$b]then Echo"$a! = $b: A! = b"ElseEcho"$a! = $b: a = b"fiif[$a-lt --A $b-GT the]then Echo"$a less than 100 and $b greater than 15: Returns True"ElseEcho"$a less than 100 and $b greater than 15: returns false"fiif[$a-lt --O $b-gt -]then Echo"$a less than 100 or $b greater than 100: Returns True"ElseEcho"$a less than 100 or $b greater than 100: returns false"fiif[$a-lt5-O $b-gt -]then Echo"$a less than 5 or $b greater than 100: Returns True"ElseEcho"$a less than 5 or $b greater than 100: returns false"fi
Result of Operation:
2. String operators:
Example of a string operator:
A="ABC"b="EFG"if[$a =$b]then Echo"$a = $b: a equals b"ElseEcho"$a = $b: A is not equal to B"fiif[$a! =$b]then Echo"$a! = $b: A is not equal to B"ElseEcho"$a! = $b: a equals b"fiif[ -Z $a]then echo"-Z $a: string length is 0"ElseEcho"-Z $a: string length is not 0"fiif[ -n $a]then Echo"-N $a: string length is not 0"ElseEcho"-N $a: string length is 0"fiif[$a]then echo"$a: string is not empty"ElseEcho"string is empty"fi
Operation Result:
3. File Test operators:
File test Operator instance:
file="/home/chunyu/ursalinkshell/test.sh"if[ -r $file]then Echo"file readable"ElseEcho"file is not readable"fiif[ -w $file]then Echo"file can be written"ElseEcho"file is not writable"fiif[ -x $file]then echo"File Executable"ElseEcho"file is not executable"fiif[ -f $file]then Echo"file is a normal file"ElseEcho"files are special files"fiif[ -d $file]then Echo"file is a directory"ElseEcho"file is not a directory"fiif[ -s $file]then Echo"the file is not empty"ElseEcho"file is empty"fiif[ -e $file]then Echo"File exists"ElseEcho"file does not exist"fi
Result of Operation:
The logical operators for Shell script programming