bash shell: the difference among 'exec', 'eval', 'source'
来源:互联网 发布:论坛制作软件 编辑:程序博客网 时间:2024/05/16 17:45
eval "translates" a value buried inside a variable, and then runs the command that was buried in there
Code:
for i in 1 2 3do eval myvar="$i" echo "$myvar"done# this gives 123# why? because there is no metavalue or special meaning to 1 or 2 or 3
Code:
for i in ls dfdo eval myvar="$i" echo "$myvar"done# here you get output from the ls command and the df command
exec starts another process - BUT - it exits the current process temporally when you do this kind of thing until the new process is finished
Code:
#!/bin/bashexec echo "leaving this script forever $0" # Exit from script here.# ----------------------------------# The following line never happensecho "This echo will never echo."
moreover, a "&" tail means that run the new process in backgroud.
source
When you run a command in the shell - like another script or a command like ls -
the shell creates a subprocess (called child process). Any environment variable that got defined or changed down in the child is LOST FOREVER to the parent process.
However if you source a script (there are two ways) you force the script to run in the current process. That means environment variables in the script you ran are NOT LOST.
Code:
# script1MYVAR="HI there!"# end script1
Code:
# script2# first, run script 1script1# now is the MYVAR variable set? No -why? it got set in the child, when the child exited it GOT LOSTecho "MYVAR= $MYVAR"# now source script1 :: putting a lonesome dot or the command "source" # in front of the script name have the same effect. script1# . script1 == source script1 these two are the SAME THINGsource script1# now is the MYVAR variable set? This time we see that MYVAR has a valueecho "MYVAR= $MYVAR"
- bash shell: the difference among 'exec', 'eval', 'source'
- eval, exec, source区别
- exec eval source
- 五种bash shell执行方式 fork, source, exec, (), {}
- the difference among C,C++ and VC++
- The Difference among size(), length() and length
- bash中exit/exec/source
- 【Bash百宝箱】shell内建命令之eval、exec、exit、export
- 【DataStructure】The difference among methods addAll(),retainAll() and removeAll()
- The difference among VIRT, RES, and SHR in top output
- shell之source exec fork
- exec、source以及bash的区别
- exec、source以及bash的区别
- 『iOS/Obj-C』The difference among int, NSInteger, NSUInteger and NSNumber
- Shell中的exec和source解析
- shell中内建命令exec、source解析
- shell中source sh exec的区别
- shell中的source及exec命令
- 搜索jar包中含有指定字符串的文件
- android Menu菜单详解
- ASCII码
- TypePerf收集服务器性能
- AS3 倒影效果(反射效果)
- bash shell: the difference among 'exec', 'eval', 'source'
- android图片特效处理之光照效果
- 原型模式 Prototype模式
- struts2.1.8 hibernate3.3.2 spring2.5 整合需要哪些jar包
- 测试学习
- WEB Service 下实现大数据量的传输
- 儿童故事-故事盒
- android图像处理(3)底片效果
- Qt使用Dom操作XML文件