Monday, April 30, 2007

Special Shell Script Variables

There are some variables which are set internally by the shell and which are available to the user:

$1 - $9   These variables are the positional parameters.
$0        The name of the command currently being executed.
$#        The number of positional arguments given to this invocation of the shell.
$?        The exit status of the last command executed is given as a decimal string.
When a command completes successfully, it returns the exit status of 0
(zero), otherwise it returns a non-zero exit status.
$$        The process number of this shell - useful for including in filenames, to
make them unique.
$!        The process id of the last command run in the background.
$-        The current options supplied to this invocation of the shell.
$*        A string containing all the arguments to the shell, starting at $1.
$@@       Same as above, except when quoted.


No comments: