Command Substitution
Command substitution permits capturing the output of any command as an argument for another command. Whenever a command line is placed inside (tilde or backquotes characters), the shell first runs the command or commands after that replaces the entire expression, involving the backquotes, with the output. This characteristic is frequently used to provide values to shell variables. Let's consider the following
# today='date'
In the given syntax this assigns the string representing the current date to the variable today.
# echo $today
This will display the output of date command.
The subsequent assignment saves, in the files variable and the number of files in the current directory:
# files='ls | wc -l'
The given command
# echo $files
It will show the total number of files in the current directory.
Command substitution can be performed on any command which writes to the standard output. To nest command substitutions, every of the nested backquotes have to be preceded through a \ (backslash), as in the given syntax
# logmsg='echo Your login directory is \'pwd\"# show the directory#
# echo $logmsg
Your login directory is /home/manu