Bash Scripting Cheat Sheet

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

${MY_VAR:-$(date +%u)}

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