Bash Script Variables

icon

Posted in one place for future reference.

  • $* - All variables as a single string/word
  • $@ - All variables but each is a separate string
  • $# - The number of arguments given
  • $0 - the name of the script
  • $1-9 - Reference each argument by number
  • $- - Flags passed to the script
  • $! - PID of last job in the background
  • $_ - The final argument of the previous command
  • $? - Exit status of the last command, function, or script
  • $$ - PID of the script

http://tldp.org/LDP/abs/html/internalvariables.html