Buy this Shell Scripting Tutorial as a PDF for only $5!
15. Quick Reference
This is a quick reference guide to the meaning of some of the less easily
guessed commands and codes of shell scripts. By their nature, they are also quite difficult to
find using search engines. These examples include process management, shell scripts arguments, and shell script test
conditions.
Command | Description | Example |
---|---|---|
& | Run the previous command in the background | ls & |
&& | Logical AND | if [ "$foo" -ge "0" ] && [ "$foo" -le "9"] |
|| | Logical OR | if [ "$foo" -lt "0" ] || [ "$foo" -gt "9" ] |
^ | Start of line | grep "^foo" |
$ | End of line | grep "foo$" |
= | String equality (cf. -eq) | if [ "$foo" = "bar" ] |
! | Logical NOT | if [ "$foo" != "bar" ] |
$$ | PID of current shell | echo "my PID = $$" |
$! | PID of last background command | ls & echo "PID of ls = $!" |
$? | exit status of last command | ls ; echo "ls returned code $?" |
$0 | Name of current command (as called) | echo "I am $0" |
$1 | Name of current command's first parameter | echo "My first argument is $1" |
$9 | Name of current command's ninth parameter | echo "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 $*" |
-eq | Numeric Equality | if [ "$foo" -eq "9" ] |
-ne | Numeric Inquality | if [ "$foo" -ne "9" ] |
-lt | Less Than | if [ "$foo" -lt "9" ] |
-le | Less Than or Equal | if [ "$foo" -le "9" ] |
-gt | Greater Than | if [ "$foo" -gt "9" ] |
-ge | Greater Than or Equal | if [ "$foo" -ge "9" ] |
-z | String is zero length | if [ -z "$foo" ] |
-n | String is not zero length | if [ -n "$foo" ] |
-nt | Newer Than | if [ "$file1" -nt "$file2" ] |
-d | Is a Directory | if [ -d /bin ] |
-f | Is a File | if [ -f /bin/ls ] |
-r | Is a readable file | if [ -r /bin/ls ] |
-w | Is a writable file | if [ -w /bin/ls ] |
-x | Is an executable file | if [ -x /bin/ls ] |
( ... ) | Function definition | function myfunc() { echo hello } |


Back: Hints and Tips Next: Interactive Shell
Appreciate this site? Please consider making a donation:
Books and eBooks
My Shell Scripting books, available in Paperback and eBook formats.
![]() Shell Scripting Tutorial is this tutorial, in 88-page Paperback and eBook formats. Convenient to read on the go, and to keep by your desk as an ever-present companion. | ![]() Shell Scripting: Expert Recipes for Linux, Bash and more is my 564-page book on Shell Scripting. The first half explains the features of the shell; the second half has real-world shell scripts, organised by topic, with detailed discussion of each script. |
Contact
You can mail me with this form. If you expect a reply, please ensure that the address you specify is valid. Don't forget to include the simple addition question at the end of the form, to prove that you are a real person!