home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: Reference: esac Chapter 4
The Bourne Shell and Korn Shell
Next: Reference: exec
 

eval



eval

 

args

Typically, eval is used in shell scripts, and args is a line of code that contains shell variables. eval forces variable expansion to happen first and then runs the resulting command. This "double-scanning" is useful any time shell variables contain input/output redirection symbols, aliases, or other shell variables. (For example, redirection normally happens before variable expansion, so a variable containing redirection symbols must be expanded first using eval ; otherwise, the redirection symbols remain uninterpreted.) See the C-shell eval (Section 5) for another example.

Example

This fragment of a Bourne shell script shows how eval constructs a command that is interpreted in the right order:

for option
do
   case "$option" in   #define where output goes
      save) out=' > $newfile' ;;
      show) out=' | more' ;;
   esac
done

eval sort $file $out


Previous: Reference: esac UNIX in a Nutshell: System V Edition Next: Reference: exec
Reference: esac Book Index Reference: exec

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System