免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1209 | 回复: 0
打印 上一主题 下一主题

subshell来龙去脉及export [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-01-04 13:17 |只看该作者 |倒序浏览

                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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP