10. Command Substitution

Command substitution replaces the output of a command with its notation. Command substitution takes place between the "$(...)" operator:

echo "Welcome, today is $(date)"
Welcome, today is Fri Oct  5 17:52:30 CEST 2012

But command substitution takes also place between the "`...`" (backticks) operator:

ls /home/`whoami`/bin/*
logrotate.sh lstree.sh pstree.sh

Command substitution is a very common in Bash. It can be nested:

$ echo $(echo $(date))
Fri Oct 5 17:53:24 CEST 2012