Name
eval
Synopsis
eval argsTypically, 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.)
Example
This fragment of a 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 $outBecome an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access