Special Shell Variables

Special Shell Variables

I always thought it will be handy to put in all the Special Shell Variables in bash somewhere.

Finally ended up writing this small article which compiles all the Special Shell Variables.

Special Shell Variables
Special Shell Variable Description
$0 This is the command name or the script name which is being executed right now.
$1 – $9 These variables are the positional parameters.
${n} Positional Parameters. Same as above, except that it takes care of variable greater than 10. For instance $11 is ${11}.
$# Provides the number of positional parameters passed/provided to the script/command.
$? Provides the exit status for the last command/script executed.
$$ Provides the Process ID/Number (PID) for the current shell.
$! Provides the process ID/Number (PID) of the previous command executed and sent in background.
$- Provides current option flags specified during invocation, by the set built-in command or set by the bash shell itself. Though this bash parameter is rarely used.
[email protected] This parameter is used to expand into positional parameters starting from one. When expansion occurs inside double quotes, every parameter expands into separate words.
$* This parameter is similar to [email protected] special bash parameter only difference is when expansion occurs with double quotes, it expands to a single word with value of each bash parameter separated by the first character of the IFS special environment variable.
$_ This is used to reference the absolute file name of the shell or bash script which is being executed as specified in the argument list. This bash parameter is also used to hold the name of mail file while checking mails.

Special Shell Variables

No Comments

Post a Comment

Time limit is exhausted. Please reload CAPTCHA.