管理员
|
阅读:1382回复:0
linux执行脚本的三种方式
楼主#
更多
发布于:2013-01-18 09:19
| | | | linux执行脚本的三种方式 目前据我所知有三种 ./bar.sh 是folk的子进程中执行. . ./bar.sh 是把./bar.sh的内容读取到当前运行环境开始执行 exec ./bar.sh 是把当前进程替换为./bar.sh的进程. 假设有脚本foo.sh python代码 #!/bin/sh A="hello"; echo "before,A is $A" ./bar.sh echo "after ,A is $A" 脚本bar.sh Python代码 #!/bin/sh A="world"; 执行foo.sh后输出如下 before,A is hello after ,A is hello 因为bar.sh是在子进程中执行的,不会影响父进程的变量. 改成 . ./bar.sh后输出为 before,A is hello after ,A is world 因为bar.sh的内容被提到了父进程中执行了. 然后改为exec ./bar.sh后输出为 before,A is hello 因为父进程被替换了,所以执行完了子进程之后,后面的语句就不执行了.
| | | | |
|