Shell和环境变量之间的区别 [英] Difference between shell and environment variables
问题描述
shell和环境变量之间有什么区别? 这些变量存储在哪里?
What are the differences between shell and environment variables? Where are these variables stored?
推荐答案
引用此来源,
标准UNIX变量分为 两类,环境变量 和外壳变量.从广义上讲, shell变量仅适用于 shell的当前实例和 用于设定短期工作 情况;环境变量有 更深远的意义,以及 在登录时设置的内容对 会话的持续时间.经过 约定,环境变量有 大写和外壳变量有 小写的名字.
Standard UNIX variables are split into two categories, environment variables and shell variables. In broad terms, shell variables apply only to the current instance of the shell and are used to set short-term working conditions; environment variables have a farther reaching significance, and those set at login are valid for the duration of the session. By convention, environment variables have UPPER CASE and shell variables have lower case names.
要列出所有环境变量,请使用printenv
,要列出所有shell变量,请使用set
.
To list all environment variables, use printenv
and to list all shell variables, use set
.
您会注意到环境变量存储了更多的永久值,例如:
You'll note that the environment variables store more permanent value, e.g.:
HOME=/home/adam
更改很少,而shell变量则存储本地的,临时的,特定于shell的值,例如:
Which changes quite seldom, while the shell variables stores local, temporary, shell-specific values, e.g.:
PWD=/tmp
每次更改当前目录时都会更改.
which changes every time you change your current directory.
对于大多数实际任务,通过在您的〜/.bashrc文件中添加export VARIABLE_NAME=VALUE
来设置环境值.
For most practical tasks, set environment values by adding export VARIABLE_NAME=VALUE
to your ~/.bashrc file.
这篇关于Shell和环境变量之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!