back toc next

Command Substitution

`list`
$(list)

Example: making a temporary file

file=`mktemp tmpfile-XXXXXXX`
file=$(mktemp tmpfile-XXXXXXX)

Example: nesting command substitutions

Generation of yesterday's date:
file=backup-`expr \`date +%Y%m%d\` - 1`.tar
file=backup-$(expr $(date +%Y%m%d) - 1).tar

A much more correct and readable (thought unportable) solution uses the capabilities of GNU date:
file=backup-`date --iso -d yesterday`.tar
or
file=backup-`date --iso -d "1 week ago"`.tar