source命令使用

实验:

#a.sh
#!/bin/sh
#a="hi"
export a=123

 

 

#b.sh 

#!/bin/sh

./a.sh
echo $a

 

 

#c.sh

#!/bin/sh
source ./a.sh
echo $a

 

 

[dengwei@localhost shell]$ ./a.sh

[dengwei@localhost shell]$ echo $a
[dengwei@localhost shell]$ ./b.sh
[dengwei@localhost shell]$ echo $a
[dengwei@localhost shell]$ ./c.sh
123
[dengwei@localhost shell]$ echo $a
[dengwei@localhost shell]$

 

 ==============

 

source 命令可以影响执行脚本的shell的环境,export 则只能影响其shell的环境。 .命令另外新建一个进程,所以.xx.sh 里面的export只在 新建的进程中有效。


 

source filename [arguments]

              Read and execute commands from filename in the current shell environment and return the exit status of the last command executed from filename.  

posted @ 2012-10-12 15:02  邓维  阅读(326)  评论(0编辑  收藏  举报