13.10. Command Substitution

13.10.1. Backquotes

A string or variable can be assigned the output of a UNIX command by placing the command in backquotes. This is called command substitution. (On the keyboard, the backquotes are normally below the tilde character.) If the output of a command is assigned to a variable, it is stored as a wordlist or array. (See “Wordlists and Command Substitution” on page 919.)

Example 13.77.
1   > echo The name of my machine is 'uname -n'.
						The name of my machine is stardust.

2   > echo The present working directory is 'pwd'.
						The present working directory is /home/stardust/john.

3   > set d = 'date'
    > echo $d
						Tue Mar 28 14:24:21 PDT 2001
					

EXPLANATION

  1. The UNIX command uname -n is enclosed in backquotes. When the shell ...

Get UNIX® Shells by Example, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.