Commonly Used Built-In Shell Variables

List of commonly used built-in shell variables – not a comprehensive list
$#  –  The number of command-line arguments used in the last command
$-   –  Options currently in effect
$?   –  Exit value of the last command – 0 for success
$$   –  Process ID of the shell
$!    –  Process ID of the last background command
$0   – The first word of the last command – i.e. the command itself
$n   – Individual arguments on the command line by position starting with 0 for the command – bash allows n to be greater than 9 if specified as ${n}
$*   – All arguments on the command line – $@ does the same thing
“$*”- All arguments on the command line – as a string
BASH – Full path name used to invoke bash
 
 

Leave a Comment

Scroll to Top