在shell中运行以不同方式运行脚本

在shell当中,可以有3中方式运行脚本:

1 . ./script_name 或者source ./script_name

2 直接./script_name

3 ./script_name &

加入脚本script_name中有两个命令command1,command2,那么,当以第一种方式运行时,command1和command2都在当前shell中运行,并没有产生subshell,如下图所示:

当script_name以第2中方式运行时,当前shell会产生一个subshell,command1和command2在subshell中运行,而当前的shell会一直等待subshell运行结束之后才继续运行,如下图所示:

当script_name以第3种方式运行时,当前shell会产生一个subshell,command1和command2在subshell中运行,但是,当前shell不会等待shubshell运行结束后再运行,而是同时和subshell一起继续运行,如下图所示:

posted @ 2016-07-31 18:28  chaoguo1234  阅读(380)  评论(0编辑  收藏  举报