Skip to content

Instantly share code, notes, and snippets.

@rezigned
Created April 2, 2012 17:11
Show Gist options
  • Save rezigned/2285236 to your computer and use it in GitHub Desktop.
Save rezigned/2285236 to your computer and use it in GitHub Desktop.
Shell options reference
# Expressions
-a # file exists
-f # file exists and is a regular file
-h # file exists and is a symbolic link
-r # file exists and is readable
-w # ... and is writable
-x # ... and is executable
-S # ... and is a socket
# Special Vars
$1 - $9 # positional arguments
$0 # command name e.g. "./test.sh cmd" where `cmd` is command
$# # number of arguments
$? # exit status of last command
$$ # process number of this shell
$! # process id of last command run in the background
$- # the current options supplied to this invocation of the shell.
$* # a string containing all the arguments to the shell, starting at $1.
$@ # same as above, except when quoted.
# Notes
$* and $@ when unquoted are identical and expand into the arguments.
$* # is a single word, comprising all the arguments to the shell, joined together with spaces. For example '1 2' 3 becomes "1 2 3".
$@ # is identical to the arguments received by the shell, the resulting list of words completely match what was given to the shell. For example '1 2' 3 becomes "1 2" "3"
# References http://unixhelp.ed.ac.uk/scrpt/scrpt2.2.2.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment