gpt4 book ai didi

linux - shell和环境变量的区别

转载 作者:IT王子 更新时间:2023-10-29 00:15:15 27 4
gpt4 key购买 nike

shell 和环境变量有什么区别?这些变量存储在哪里?

最佳答案

引用 this source ,

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

您会注意到环境变量存储更多永久值,例如:

HOME=/home/adam

很少更改,而 shell 变量存储本地的、临时的、特定于 shell 的值,例如:

PWD=/tmp

每次您更改当前目录时都会更改。

对于大多数实际任务,通过将 export VARIABLE_NAME=VALUE 添加到您的 ~/.bashrc 文件来设置环境值。

关于linux - shell和环境变量的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3341372/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com