Bash Scripting Cheat Sheet

if FOO is null, then null or (:) empty use default

${MY_VAR-MyValue4Null}
${MY_VAR:-MyValue4NullOrEmpty}
${MY_VAR:-$OTHER_VAR}
${MY_VAR:-$(date +%u)}
http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/WebappTesting.html

Redirecting Outputs

# Redirect stdout ( > ) into a named pipe ( >() ) running "tee"
exec > >(tee logfile.txt)

# Without this, only stdout would be captured - i.e. your
# log file would not contain any error messages.
# SEE answer by Adam Spiers, which keeps STDERR a seperate stream -
# I did not want to steal from him by simply adding his answer to mine.
exec 2>&1

echo "foo"
echo "bar" >&2
http://stackoverflow.com/questions/3173131/redirect-copy-of-stdout-to-log-file-from-within-bash-script-itself