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

26.4. eval

The eval command will evaluate the command line to complete any shell substitutions and will then execute it. Eval is used to expand variables where one pass of the expansion does not do the job; eval makes two passes through a variable to expand it. Variables that require two passes to evaluate are sometimes called complex variables. Take it from me, variables are not complex.

Eval can still be used to echo out simple variables; they do not have to be complex variables.

						$ NAME=Honeysuckle 
$ eval echo $NAME 
Honeysuckle 
$ echo $NAME 
Honeysuckle
					

The best way to explain how eval works is to see it on the command line as it evaluates.

26.4.1. Executing commands held in a string

Let’s first create a little file called testf that holds ...

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