简体   繁体   English

设置变量与环境变量Linux(debian)Bash shell

[英]Set variables versus env variables Linux(debian) Bash shell

When creating set variables, what is the advantage of adding them to environment? 创建设置变量时,将其添加到环境中有什么好处? Both are lost at session termination. 两者都在会话终止时丢失。 I know obviously I can add useful stuff to .bashrc that I would want to access via my user. 我知道很明显,我可以向.bashrc添加一些有用的东西,这些东西我想通过我的用户访问。 Just not sure what the advantages would be? 只是不确定会有什么优势? how common practice is it? 这是常见的做法? do I need to worry about it? 我需要担心吗? I am talking real life administration uses. 我说的是现实生活中的行政用途。

It seems to me like set is a local variable within a class. 在我看来,set是类中的局部变量。 ENV is obviously global. ENV显然是全球性的。 Maybe the only use is when traversing different shells? 也许唯一的用处是遍历不同的外壳时? How practical is it? 这有多实用?

Environment variables are inherited by any process invoked by your shell. 环境变量由您的Shell调用的任何进程继承。 That includes both sub-shells and any other commands you invoke. 这包括子外壳程序和您调用的任何其他命令。

(Non-environment) shell variables are not. (非环境)shell变量不是。

For example, $TERM needs to be exported, because commands you invoke from your shell (a text editor, a pager, anything that uses a full-screen text display) needs to know what kind of terminal you're using, so it can look up its capabilities in termcap or terminfo. 例如, $TERM需要导出,因为您从外壳程序(文本编辑器,寻呼机,使用全屏文本显示的任何内容)调用的命令需要知道您使用的终端类型,因此可以在termcap或terminfo中查找其功能。 $LANG and similar variables need to be exported so that commands know about the current locale. $LANG和类似的变量需要导出,以便命令知道当前的语言环境。 $PATH needs to be exported so that any commands you invoke can then invoke other commands. $PATH需要导出,以便您调用的任何命令都可以随后调用其他命令。

$PS1 , the shell prompt, does not need to be exported, because it's relevant only to the current shell (and is typically initialized for new shells). 不需要导出$PS1 (shell提示符),因为它仅与当前shell相关(并且通常针对新shell初始化)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM