Last Updated: February 25, 2016
·
1.563K
· benjaminrh

Special $ (dollar) shell variables

If you use Linux or another UNIX-like operating system and find yourself forgetting exactly which $ prefixed command does what, this is for you:

  • $$ - the PID of the current process
  • $! - the PID of the most recent background process
  • $? - the most recent exit code
  • $# - the number of passed parameters
  • $* / $@ - a string / array of the passed parameters
  • $_ - the most recent parameter
  • $0 - script/program name (0th parameter)
  • $1...$9 - positional parameters 1 through 9
  • $NAME - references environment variable "NAME"