Command substitution in the Bourne shell

Command substitution allows you to capture the output of any command as an argument to another command.

When you place a command line within backquotes (``), the shell first runs the command or commands and then replaces the entire expression, including the backquotes, with the output. This feature is often used to give values to shell variables. For example, the statement:
today=`date`
assigns the string representing the current date to the today variable. The following assignment saves, in the files variable, the number of files in the current directory:
files=`ls | wc -l`

You can perform command substitution on any command that writes to standard output.

To nest command substitutions, precede each of the nested backquotes with a backslash (\), as in:
logmsg=`echo Your login directory is \`pwd\``
You can also give values to shell variables indirectly by using the read special command. This command takes a line from standard input (usually your keyboard) and assigns consecutive words on that line to any variables named. For example:
read first init last
takes an input line of the form:
J. Q. Public
and has the same effect as if you had typed:
first=J. init=Q. last=Public

The read special command assigns any excess words to the last variable.