O'Reilly logo

Korn Shell: Unix and Linux Programming Manual, Third Edition, The by Anatole Olczak

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

The eval Command

The eval command reads and executes commands using the following format:

					eval
					commands
				

It causes commands to be expanded twice. For simple commands, there is no difference in execution with or without eval:

					$ eval print ∼
					/home/anatole
				

Here is a more complicated command that illustrates the use of eval. We want the contents of the stext file redirected when variable X is accessed.

					$ cat stext
					She sells seashells by the seashore.
				

First, variable X is set to "<stext":

					$ X="<stext"
				

When the value of X is printed using simple variable expansion, it generates an error:

					$ cat $X
					<stext: No such file or directory
				

Using the eval command, X is first expanded to <stext, then the command cat <stext is executed. This causes the ...

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