3. Shell comparison operator & reference

CommandDescriptionExample
&Run the previous command in the backgroundls &
&&Logical ANDif [ "$X" -ge "0" ] && [ "$X" -le "9"]
||Logical ORif [ "$X" -lt "0" ] || [ "$X" -gt "9" ]
^Start of linegrep "^X"
$End of linegrep "X$"
=String equality (cf. -eq)if [ "$X" = "bar" ]
!Logical NOTif [ "$X" != "bar" ]
$$PID (Process ID)of current shellecho "my PID = $$"
$!PID of last background commandls & echo "PID of ls = $!"
$?exit status of last commandls ; echo "ls returned code $?"
$0Name of current command (as called)echo "I am $0"
$1Name of current command’s first parameterecho "The first argument is $1"
$9Name of current command’s ninth parameterecho "The ninth argument is $9"
$@All of current command’s parameters (preserving whitespace and quoting)echo "The arguments are $@"
$*All of current command’s parameters (not preserving whitespace and quoting)echo "The arguments are $*"
-eqNumeric Equalityif [ "$X" -eq "9" ]
-neNumeric Inqualityif [ "$X" -ne "9" ]
-ltLess Thanif [ "$X" -lt "9" ]
-leLess Than or Equalif [ "$X" -le "9" ]
-gtGreater Thanif [ "$X" -gt "9" ]
-geGreater Than or Equalif [ "$X" -ge "9" ]
-zString is zero lengthif [ -z "$X" ]
-nString is not zero lengthif [ -n "$X" ]
-ntNewer Thanif [ "$file1" -nt "$file2" ]
-otOlder Thanif [ “$file1” -ot “$file2” ]
-dIs a Directoryif [ -d /bin ]
-fIs a Fileif [ -f /bin/ls ]
-rIs a readable fileif [ -r /bin/ls ]
-wIs a writable fileif [ -w /bin/ls ]
-xIs an executable fileif [ -x /bin/ls ]
-a-efile exists
-efPaths refer to the same file
-OFile is owned by the user running the test
-SDenotes Socket File
( … )Function definitionfunction thefunc() { echo hello world }