<tt>`...`</tt>: Use Output as Content of Variable



next up previous contents
Next: Verbatim echo Up: Special Characters Previous: ;;...;;: Turn off

`...`: Use Output as Content of Variable

To give a variable the value of the output of a command, one uses back quotes:

sh_prompt> VARI="me"
sh_prompt> echo $VARI
me
sh_prompt> OTHER=`echo $VARI`
sh_prompt> echo $OTHER
me

The output of the command within the back quotes is taken to be the new content of the first variable. Another short example:

sh_prompt> TODAY=`date`
sh_prompt> echo $TODAY
Mon Aug 20 17:35:51 EDT 1990
sh_prompt> echo "today's date is $TODAY"
today's date is Mon Aug 20 17:35:51 EDT 1990

Note that by default, the output of a series of commands is sent to the standard output. If the output is preceded by an = sign, the variable preceding the equal sign takes the value of the output of the command.



Super-User
Fri Feb 17 15:55:40 EST 1995