Command substitution is a feature that allows output to be expanded from a command. It can be used to assign the output of a command to a variable, or to imbed the output of a command within another command. The format for command substitution is:
where command is executed and the output is substituted for the entire $(command) construct. For example, to print the current date in a friendly format:
$ echo The date is $(date) The date is Fri Jul 27 10:41:21 PST 1996
or see who is logged on:
$ echo $(who —q) are logged on now root anatole are logged on now
Any commands can be used inside $(...), including pipes, I/O operators, metacharacters (wildcards), and more. We can find out how many users are logged ...