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

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.