O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required