Shell Variables

Image of Author
February 28, 2022 (last updated September 21, 2022)
  • $@ is a list of all the parameters passed in to a function
  • $# is the number of parameters passed in to a function
function idk() {
  echo $@
  echo $#
}

idk hey
1
hey

idk hey yall
2
hey yall
  • $? is the exit status of the last ran function
which cat
/bin/cat
echo $?
0 # This is good
which
echo $?
1 # This is bad (an error because no argument was provided)
+
zsh: command not found: +
echo $?
127 # This is bad too (127 means "command not found")
  • $1, $2, ..., represent variables used inside of functions.
myecho() { echo $1 }
myecho "hey"
"hey"