子外壳何时会继承其父外壳环境? [英] When does a sub shell inherits its parent shell env?

查看:56
本文介绍了子外壳何时会继承其父外壳环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在什么情况下外壳环境会传递给子外壳?

Under what circumstances is the environment of the shell passed to the sub-shell?

推荐答案

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

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.

这篇关于子外壳何时会继承其父外壳环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆