|
发表于 2009-2-25 21:21:28
|
显示全部楼层
楼上两位哥儿的回复挺令人汗颜的啊,尤其是头一遭听闻这个...Post by poet;1951416
对于这个问题我的理解是:[color="Blue"]父 shell 只能继承子 shell 用 export 导出的变量,而子 shell 可以继承父 shell 的所有变量。 完全错误!
shell确实有很多看似不符合常理的情况,但是manpage里全部交代清楚了!- [color="Red"]Command substitution, commands grouped with parentheses, and asynchro-
- nous commands are invoked in a subshell environment that is a duplicate
- of the shell environment, except that traps caught by the shell are
- reset to the values that the shell inherited from its parent at invoca-
- tion.[/color] Builtin commands that are invoked as part of a pipeline are also
- executed in a subshell environment. Changes made to the subshell envi-
- ronment cannot affect the shell's execution environment.
复制代码 shell environment 里到底包括了些什么?往上翻阅manpage!- The shell has an execution environment, which consists of the follow-
- ing:
- o open files inherited by the shell at invocation, as modified by
- redirections supplied to the exec builtin
- o the current working directory as set by cd, pushd, or popd, or
- inherited by the shell at invocation
- o the file creation mode mask as set by umask or inherited from
- the shell's parent
- o current traps set by trap
- [color="Red"] o shell parameters that are set by variable assignment or with set
- or inherited from the shell's parent in the environment[/color]
- o shell functions defined during execution or inherited from the
- shell's parent in the environment
- o options enabled at invocation (either by default or with com-
- mand-line arguments) or by set
- o options enabled by shopt
- o shell aliases defined with alias
- o various process IDs, including those of background jobs, the
- value of $$, and the value of $PPID
复制代码 至少在楼主提问之前我不晓得怎么回答这个问题,manpage给了我最好的答案。谢谢楼主!谢谢manpage! |
|