10.10. Command Substitution

10.10.1. Backquotes

A string or variable can be assigned the output of a Linux command by placing the command in back quotes. This is called command substitution. (On the keyboard, the back quotes 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" .)

Example 10.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 2000
					

Explanation

  1. The Linux command uname -n is enclosed in back quotes. When the shell encounters ...

Get Linux Shells by Example 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.