Click Here to buy the full 85-page PDF for only £4.99, $9.99 or €6.99,
or the Kindle eBook or Paperback (UK here - more countries and details here)

Shellshock Have you come to find out about ShellShock? Click here

15. Quick Reference

This is a quick reference guide to the meaning of some of the less easily guessed commands and codes.
CommandDescriptionExample
&Run the previous command in the backgroundls &
&&Logical ANDif [ "$foo" -ge "0" ] && [ "$foo" -le "9"]
||Logical ORif [ "$foo" -lt "0" ] || [ "$foo" -gt "9" ] (not in Bourne shell)
^Start of linegrep "^foo"
$End of linegrep "foo$"
=String equality (cf. -eq)if [ "$foo" = "bar" ]
!Logical NOTif [ "$foo" != "bar" ]
$$PID 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 "My first argument is $1"
$9Name of current command's ninth parameterecho "My ninth argument is $9"
$@All of current command's parameters (preserving whitespace and quoting)echo "My arguments are $@"
$*All of current command's parameters (not preserving whitespace and quoting)echo "My arguments are $*"
-eqNumeric Equalityif [ "$foo" -eq "9" ]
-neNumeric Inqualityif [ "$foo" -ne "9" ]
-ltLess Thanif [ "$foo" -lt "9" ]
-leLess Than or Equalif [ "$foo" -le "9" ]
-gtGreater Thanif [ "$foo" -gt "9" ]
-geGreater Than or Equalif [ "$foo" -ge "9" ]
-zString is zero lengthif [ -z "$foo" ]
-nString is not zero lengthif [ -n "$foo" ]
-ntNewer Thanif [ "$file1" -nt "$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 ]
parenthesis:
( ... )
Function definitionfunction myfunc() { echo hello }
Click Here to buy the full 85-page PDF for only £4.99, $9.99 or €6.99,
or the Kindle eBook or Paperback (UK here - more countries and details here)

Shellshock Have you come to find out about ShellShock? Click here
Steve's Bourne / Bash shell scripting tutorial
Share on Twitter Share on Facebook Share on LinkedIn Share on Identi.ca Share on StumbleUpon

Get the Book:

Buy my 600-page Shell Scripting Book...


Or from other Amazon in other countries: USA, Germany, France, Spain, Italy, Canada, Japan, India, Brazil
Or from other retailers

Buy this Tutorial in Paperback or for Kindle:


USA, UK, Germany, France, Spain, Italy
Or Kindle in these countries: Canada, Australia, Japan, India, Brazil, Mexico

Buy this Tutorial as a DRM-Free PDF

(Free Sample)

$9.99 US Dollars

£4.99 UK Pounds

€6.99 Euros

You can join our Shell Scripting community on Facebook:

DefectiveByDesign.org