- 论坛徽章:
- 0
|
1.创建子shell时机:
When you log into a Linux system, you execute an initial login shell. This initial shell executes any simple commands that you enter. However, there are several circumstances when your current shell (the parent process) creates a new shell (a child process) to perform some tasks:
1.1命令组
When a grouped command is executed, such as (ls; pwd; date), the parent shell creates a child shell to execute the grouped commands. If the command is not executed in the background, the parent shell sleeps until the child shell terminates.
1.2.执行脚本时
When a script is executed, the parent shell creates a child shell to execute the commands in the script. If the script is not executed in the background, the parent shell sleeps until the child shell terminates.
1.3.后台工作
When a background job is executed, the parent shell creates a child shell to execute the background commands. The parent shell continues to run concurrently with the child shell.
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:
F:\pic_upload\
![]()
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(也是一种程式);
F:\pic_upload\a.jpg
F:\pic_upload\a.png
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/103643/showart_2138830.html |
|