且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

子外壳何时会继承其父外壳环境?

更新时间:2023-02-02 14:03:23

子外壳程序始终从父外壳程序中获取所有变量.

A subshell always gets all variables from the parent shell.

man bash 将描述使用子shell的所有情况,主要是:命令& 命令|命令(命令)

man bash will describe all the circumstances in which a subshell is used, which are mainly: command & command | command and ( command )

所谓的环境仅包含环境变量( export变量),并传递给每个子进程.即使调用 bash -c命令,它也不是子shell,而是全新的bash实例.

The so called environment only includes environment variables (export variable), and is passed on to every sub-process. Even when invoking bash -c command, which is not a sub-shell but a completely new bash instance.

在两种情况下,更改后的值都不会传递回父进程.

In both cases changed values are not passed back to the parent process.