全部博文(48)
分类: LINUX
2010-01-04 13:17:44
1.脚本执行方式
./a.sh //需x权限 创建子shell(非交互式bash)
bash ./a.sh == bash a.sh //无需可执行权限 用bash来执行, a.sh作为参数
source ./a.sh == source a.sh //无需可执行权限 当前shell下执行
exec ./a.sh //需x权限 -bash被终止变成非交互式bash ( /bin/bash /home/garylv/tmp/a.sh )
所谓source就是让script在当前shell内执行、而不是产生一个sub-shell来执行;
exec也是让script在同一个进程上执行,但是原有进程则被结束了;
2.工作目录
A child shell is often called a subshell. Just like any other Linux process, a subshell has its own current working directory, and so cd commands executed in a subshell do not affect the working directory of the parent shell:
3.Data Area
Every shell contains two data areas: an environment space and a local variable space. A child shell inherits a copy of its parent's environment space and a clean local variable space
Figure Child shell data spaces.
PS:
Shell scripts 仅是利用shell(eg bash)这支程序的功能进行一些判断,而最终执行的除了bash提供的功能外,仍是呼叫一些已经编译好的binary来执行;
Bash本身就是binary;
<UNIX小字典——环境变数与变数>
在UNIX里面,这是一个不讲还好、越讲越搞不清楚的观念。简单的说,所谓的<环境变数>就是此变数能够告诉所有的程式使用者目前所处的环境,而变数则不能,因为只有Shell 能看到变数,而环境变数是所有的程式都能够看到的。例如所有的程式( 自身和子进程)都需要知道TERM这个变数,所以它是一个环境变数。在sh下面的export命令可以想作:让大家都能看到这个变数。
export针对的是程式,不单单是shell(也是一种程式);