My new 564-page book, Shell Scripting, published by Wiley, is on sale now. Please click "Like" on the left if you are on Facebook, or just click here to get the book.
15. Quick Reference
This is a quick reference guide to the meaning of some of the less easily
guessed commands and codes.
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" ] (not in Bourne shell)
^
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)
My new 564-page book, Shell Scripting, published by Wiley, is on sale now. Please click "Like" on the left if you are on Facebook, or just click here to get the book.