Command Substitution
`list`
$(list)
- This is one possible way to assign the output of a process to a variable
- Backticks are the portable way to perform a command substitution
- $() if a bash-ism, but it is easier to nest command substitutions (if needed)
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