Characters significant to shells "sh" and "bash": WH 1996/9, 2009/01 Character(s): Significance: | form a pipe between surrounding commands || do following command only if previous fails (C logical or) && do following command only if previous succeeds (C logical and) ; OR newline terminate previous command & run previous command in background > redirect "stdout" by sending output to the following file >> redirect "stdout" by appending output to the following file < redirect "stdin" by getting input from following file << take input from the "here" document (special syntax) - input to come from the following lines ' ' encloses a string preventing shell from touching it " " encloses a string preventing shell from touching it EXCEPT that variable subs $ and command subs ` ` are done $ variable substitution: evaluate variable - replace by value By convention, an environment (exported) variable is all CAPs. Use ${ } where ambiguity is possible. Modifiers available. Special variables: (Note all numbers are decimal.) $0 command name $1,$2,... parameters given with command (see also: "shift", "set") $* $1 $2 ... thus "$*" is "$1 $2 ..." $@ $1 $2 ... except "$@" is "$1" "$2" ... $# number of parameters supplied to command $? exit status of last command $$ process number of this shell: use to generate temporary names $! process number of last command run in background $- flags supplied to shell = Variable assignment when in a string: VARIABLE=value Never put spaces around '=' and quote value if has spaces or other characters significant to shell. ` ` command substitution: execute the enclosed commands and replace by output. In bash can also use: $( ) It nests! ( ) enclosed commands are run in subshell, a separate environment. { } command grouping (){ } used for shell functions: function_name () { commands ; } . execute commands from given file in the current shell and environment, not in a subshell: "source" the file # comment : null command - do not use it like a comment ": hi ; trouble" \ escape or quote character: next character is taken literally losing significance to the shell. However, don't use inside a ' ' since no character has special significance there. \newline is ignored so can use this to continue a line. [ ] synonym for "test" but make sure [ and ] surrounded by spaces [[ ]] improved builtin "test" for "bash" - for conditional expressions (( )) arithmetic expression in "bash". $(( )) gives value FILE REFERENCE characters: Note that '/' and '.' when initial or just after '/' must be matched explicitly. / directory * replace by any string (even a null one) ? replace by any single character [ ] replace by any single character of given kind, as in: [abcd] list of characters (a,b,c,d) [a-z] - range of characters (a,b,c,...,z) [!abq-z] ! not these characters (not a,b,q,r,...,y,z) ~ "bash" only - home directory of user "csh": ! history substitution: replace by value as determined from this or previous command lines