System information
An Introduction to Shells in General
Axis Communications AB provides NO support for application development of any kind. The information
here is provided "as is", and there is no guarantee that any of the examples shown will work in your
particular application.
Revision 1.02 October 2002 65
Variable Symbol Description
$@
Contains the argument list. By itself, $@ is equivalent to $1, $2 and so
on up to the number of arguments. The construct "$@" is equivalent to
"$1", "$2" ...., which preserves the argument list. Without quotes, $@
divides arguments containing spaces into separate arguments.
5.7 The importance of Quotation Marks
The use of the different types of quotation marks is very important in shell programming. To
perform different functions, the shell uses both kinds of quotation marks and the backslash
character. The double quotation marks (""), the single quotation marks (''), and the backslash (\)
are all used to hide special characters from the shell. Each of these methods hides varying
degrees of special characters from the shell.
Double quotation marks are the least powerful of the three methods. When you surround
characters with double quotes, all the white space characters are hidden from the shell, but all
other special characters are still interpreted. This type of quoting is most useful when you are
assigning strings that contain more than one word to a variable. For example, if you wanted to
assign the string hello world to the variable hello, you would type the following command:
hello="hello world"
This command would store the string hello world into the variable hello as one word.
Single quotes are the most powerful form of quoting. They hide all special characters from the
shell. This is useful if the command you enter is intended for a program other than the shell.
greeting="hello there $LOGNAME"
This would store the value hello there root into the variable greeting if you were logged
in as root. If you tried to write this command using single quotes it wouldn't work, because the
single quotes would hide the dollar sign from the shell and the shell wouldn't know that it was
supposed to perform a variable substitution. The variable greeting would be assigned the
value hello there $LOGNAME if you wrote the command using single quotes.
Backslash quoting is used most often when you want to hide only a single character from the
shell. This is usually done when you want to include a special character in a string. For example,
if you wanted to store the price of a box of computer disks into a variable named disk_price,
you would use the following command:
disk_price=\$5.00
The backslash in this example would hide the dollar sign from the shell. If the backslash were
not there, the shell would try to find a variable named 5 and perform a variable substitution on
that variable. Assuming that no variable named 5 were defined, the shell would assign a value of
.00 to the disk_price variable. This is because the shell would substitute a value of null for
the $5 variable.