Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Special variables in Unix shells? [closed]

Tags:

shell

unix

I need a good reference on unix shell special variables (csh, ksh and bash).

e.g. $1, $*, $#, etc.

like image 290
Michael Ellick Ang Avatar asked Jul 08 '10 17:07

Michael Ellick Ang


1 Answers

From the Linux Documentation Project (with additional $_ variable) :

$* Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the IFS special variable.

$@ Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word.

$# Expands to the number of positional parameters in decimal.

$? Expands to the exit status of the most recently executed foreground pipeline.

$- A hyphen expands to the current option flags as specified upon invocation, by the set built-in command, or those set by the shell itself (such as the -i).

$$ Expands to the process ID of the shell.

$! Expands to the process ID of the most recently executed background (asynchronous) command.

$0 Expands to the name of the shell or shell script.

$_ The underscore variable is set at shell startup and contains the absolute file name of the shell or script being executed as passed in the argument list. Subsequently, it expands to the last argument to the previous command, after expansion. It is also set to the full pathname of each command executed and placed in the environment exported to that command. When checking mail, this parameter holds the name of the mail file.

like image 188
kzh Avatar answered Sep 26 '22 01:09

kzh