shell中调用shell
来源:互联网 发布:程序员招聘网站有哪些 编辑:程序博客网 时间:2024/05/15 01:28
- http://blog.sina.com.cn/s/blog_4a76def00100a98j.html点击打开链接
- fork
( /directory/script.sh)
fork是最普通的, 就是直接在脚本里面用/directory/script.sh来调用script.sh这个脚本.
运行的时候开一个sub-shell执行调用的脚本,sub-shell执行的时候, parent-shell还在。
sub-shell执行完毕后返回parent-shell. sub-shell从parent-shell继承环境变量.但是sub-shell中的环境变量不会带回parent-shell
- exec (exec /directory/script.sh)
exec与fork不同,不需要新开一个sub-shell来执行被调用的脚本.
被调用的脚本与父脚本在同一个shell内执行。但是使用exec调用一个新脚本以后, 父脚本中exec行之后的内容就不会再执行了。这是exec和source的区别
- source (source /directory/script.sh)
与fork的区别是不新开一个sub-shell来执行被调用的脚本,而是在同一个shell中执行. 所以被调用的脚本中声明的变量和环境变量, 都可以在主脚本中得到和使用.
可以通过下面这两个脚本来体会三种调用方式的不同:
1.sh
#!/bin/bash
A=B
echo "PID for 1.sh before exec/source/fork:$$"
export A
echo "1.sh: \$A is $A"
case $1 in
exec)
echo "using exec…"
exec ./2.sh ;;
source)
echo "using source…"
. ./2.sh ;;
*)
echo "using fork by default…"
./2.sh ;;
esac
echo "PID for 1.sh after exec/source/fork:$$"
echo "1.sh: \$A is $A"
2.sh
#!/bin/bash
echo "PID for 2.sh: $$"
echo "2.sh get \$A=$A from 1.sh"
A=C
export A
echo "2.sh: \$A is $A"
执行情况:
$ ./1.sh
PID for 1.sh before exec/source/fork:5845364
1.sh: $A is B
using fork by default…
PID for 2.sh: 5242940
2.sh get $A=B from 1.sh
2.sh: $A is C
PID for 1.sh after exec/source/fork:5845364
1.sh: $A is B
$ ./1.sh exec
PID for 1.sh before exec/source/fork:5562668
1.sh: $A is B
using exec…
PID for 2.sh: 5562668
2.sh get $A=B from 1.sh
2.sh: $A is C
$ ./1.sh source
PID for 1.sh before exec/source/fork:5156894
1.sh: $A is B
using source…
PID for 2.sh: 5156894
2.sh get $A=B from 1.sh
2.sh: $A is C
PID for 1.sh after exec/source/fork:5156894
1.sh: $A is C
$
- shell中调用shell
- shell 中调用另一个 shell
- shell中调用java
- python中调用shell
- shell中调用sqlplus
- shell中调用其他shell的方法
- shell中调用hbase shell命令
- shell 中调用 mysql 操作
- 在java中调用shell
- android 代码中调用shell
- python中如何调用shell
- python中如何调用shell
- C中调用shell 脚本
- python中如何调用shell
- repo 中shell 调用 python
- python中如何调用shell
- shell中调用存储过程
- android 代码中调用shell
- 热烈祝贺环融科技网站正式上线
- Mindjet 与 Trello 任务管理解决方案之一决高低
- js中cookie的使用详细分析
- SpringDateJpa使用JpaRepository方法出现空指针异常的问题
- HDU_4883 TIANKENG’s restaurant
- shell中调用shell
- JDK5.0垃圾收集优化之--Don't Pause
- OpenStack计算节点上虚拟网络(Neutron)详解
- php获取手机os
- 解释一下Windows的消息机制
- 一段旧代码 ———— linux下C语言操作mysql
- 【DP】poj2229_Sumsets_201408041139
- 未能加载文件或程序集“Microsoft.Office.Interop.Word, Version=11.0.0.0, Cultu
- 黑马程序员 java学习笔记——类加载器