转载自:http://blog.sina.com.cn/s/blog_4aec3a1d010006wi.html

eval man manual中的定义如下:
eval [arg...]
The args areread and concatenated together into a single command. Thiscommand is then read and executed by the shell,and its exit status is returned as the value ofeval. If there are no args, oronly null rguments, eval returns 0.
使用eval可以动态的组织命令。shell在解析脚本的时候要经过以系列的步骤,比如变量的替换,命令替换等。但是“”和‘’允许我们跳过某些步骤。
for i in 2 3 4; do
eval a$i=2
eval echo "\$a$i"
done

eval先进行替换,得到一个字符串,此字符串为一个shell命令,然后,eval在执行此命令。如果不用eval将只打印出a2,a3,a4。使用eval则动态创建了变量的赋值语句。很灵活。