Shell Variables

Image of Author
September 16, 2022 (last updated September 18, 2024)
  • $@ 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"