November 2015
Beginner
282 pages
5h 5m
English
The eval command is a shell builtin command used to construct a command by concatenating arguments passed to eval. A concatenated command is further executed by shell and returns a result. If no arguments are given to eval, it returns 0.
The syntax of the eval command is as follows:
eval [arg …]
The following example shows the expansion of a variable to the name of another variable using eval:
$ name=foo $ foo="Welcome to foo world" $ echo $name foo $ new_name='$'$name #new_name just stores string value $foo $ echo $new_name $foo $ eval new_name='$'$name # eval processes $foo string into variable and prints # foo variable value Welcome to foo world
Another example where eval can be useful is as follows:
$ pipe="|" $ df ...
Read now
Unlock full access