简体   繁体   中英

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. 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. ENV is obviously global. Maybe the only use is when traversing different shells? How practical is it?

Environment variables are inherited by any process invoked by your shell. That includes both sub-shells and any other commands you invoke.

(Non-environment) shell variables are not.

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. $LANG and similar variables need to be exported so that commands know about the current locale. $PATH needs to be exported so that any commands you invoke can then invoke other commands.

$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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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