15.4. Back quote

The back quote is the one to use when you want to assign output from system commands to variables. It tells the shell to take whatever is between the back quotes as a system command and execute its output. Using these methods you can then substitute the output into a variable. You can also combine quotes, as we shall see in a moment.

In the following example, the shell has tried to evaluate and substitute the word hello; because there is no command or script called hello, it responds with an error.

						$ echo `hello` 
sh: hello: command not found
					

Now let’s try again with the date command.

						$ echo `date` 
Sun May 16 16:40:19 GMT 1999
					

This time the command is valid, and the shell can evaluate it correctly.

Let’s now assign the output ...

Get Linux and Unix Shell Programming 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.