脚本执行方式(source 点. ./ sh)
有很多方式可以执行脚本,用于读取并执行test.sh中的命令,区别如下:
|
source test.sh |
执行过程不另开进程,脚本文件中设定的变量在当前shell中可以看到 |
|
. test.sh |
|
|
./test.bsh |
在当前进程另开子进程来执行脚本命令,脚本文件中设定的变量在当前shell中不能看到 |
|
sh test.sh |
liuwanpeng@ubuntu:~$ cat test.sh echo "pid in test.sh" $$ var=123 liuwanpeng@ubuntu:~$ echo $$ 8574 liuwanpeng@ubuntu:~$ unset var;source test.sh ;echo $var pid in test.sh 8574 liuwanpeng@ubuntu:~$ unset var;. test.sh ;echo $var pid in test.sh 8574 123 liuwanpeng@ubuntu:~$ unset var;./test.sh ;echo $var pid in test.sh 8670 iuwanpeng@ubuntu:~$ unset var;sh test.sh ;echo $var pid in test.sh 8671

浙公网安备 33010602011771号