Skip to content

Instantly share code, notes, and snippets.

@mfurlend
Created January 5, 2017 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mfurlend/0aaa7356b23ce3ab693b402b95af1686 to your computer and use it in GitHub Desktop.
Save mfurlend/0aaa7356b23ce3ab693b402b95af1686 to your computer and use it in GitHub Desktop.
Bash - Special Variables
  • $1, $2, $3, ... are the positional parameters.
  • "$@" is an array-like construct of all positional parameters, {$1, $2, $3 ...}.
  • "$*" is the IFS expansion of all positional parameters, $1 $2 $3 ....
  • $# is the number of positional parameters.
  • $- current options set for the shell.
  • $$ pid of the current shell (not subshell).
  • $_ most recent parameter (or the abs path of the command to start the current shell immediately after startup).
  • $IFS is the (input) field separator.
  • $? is the most recent foreground pipeline exit status.
  • $! is the PID of the most recent background command.
  • $0 is the name of the shell or shell script.

Most of the above can be found under Special Parameters in the Bash Reference Manual. There are all the environment variables set by the shell.

For a comprehensive index, please see the Reference Manual Variable Index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment