eval 的含义 (copied)
来源:互联网 发布:企查查同类软件 编辑:程序博客网 时间:2024/05/16 14:47
up vote20down vote
eval
is part of POSIX. Its an interface which can be a shell built-in.
Its described in the "POSIX Programmer's Manual": http://www.unix.com/man-page/posix/1posix/eval/
eval - construct command by concatenating arguments
It will take an argument and construct a command of it, which will be executed by the shell. This is the example of the manpage:
1) foo=10 x=foo2) y='$'$x3) echo $y4) $foo5) eval y='$'$x6) echo $y7) 10
- In the first line you define
$foo
with the value '10' and$x
with the value 'foo'. - Now define
$y
, which consists of the string '$foo'. The dollar sign must be escaped with '$'. - To check the result,
echo $y
. - The result will be the string '$foo'
- Now we repeat the assignment with
eval
. It will first evaluate$x
to the string 'foo'. Now we have the statementy=$foo
which will get evaluated toy=10
. - The result of
echo $y
is now the value '10'.
This is a common function in many languages, e.g. Perl and JavaScript. Have a look at perldoc eval for more examples: http://perldoc.perl.org/functions/eval.html
0 0
- eval 的含义 (copied)
- Eval的含义
- EVAL的含义
- ksh/bash的提示符修改 (copied)
- BASH的双引号,单引号示例 (copied)
- 免费的文本编辑器 (copied)
- awk 例子 (copied)
- 安装Oracle Tuxedo 的RP包的方法 (copied)
- 有关标注(记)表达式的更多信息 (copied)
- CVS 查看指定branch的revision (copied)
- 滚动查看正在生成的log (copied)
- DOS批处理,灵活延迟,带有参数的延迟 (copied)
- Vim一些容易忘记的命令 (copied)
- Java语言与C++语言的差异总结 (copied)
- 自动生成Makefile的详细过程 (copied)
- makefile的特殊变量,类似$@, $+等 (copied)
- putty常用设置 (copied)
- vimdiff使用技巧 (copied)
- ExtJS3 所有类
- Android笔记-Dialog,动画,传感器等
- 深入理解HTTP协议(图文版)
- python 读取xml文档
- java中byte转换int时为何与0xff进行与运算
- eval 的含义 (copied)
- mysql数据库中的各字段类型概述
- js系列:时间格式转成时间戳和比较某个时段是否在另一个时间段内
- PHP CURL_EXEC和 curl_setopt($ch,CURLOPT_RETURNTRANSFER, 0);1,0参数详解
- Java 知识点补充
- java调用ocx方法
- CssShake
- 预定义宏__LINE__,__FILE__解析
- cocos2dx交叉编译报错No rule to make target...CCConfiguration.o.stop
eval
is a built-in, not a function. In practice, built-ins behave a lot like functions that don't have an in-language definition, but not quite (as becomes apparent if you are twisted enough to define a function calledeval
). – Gilles Oct 23 '11 at 1:17来源:http://unix.stackexchange.com/questions/23111/what-is-the-eval-command-in-bash