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.