Ric*_*ani 3 macos zsh environment-variables iterm2 direnv
我想做的事
$ echo $USERNAME
myusername
$ export USERNAME=newvalue
$ echo $USERNAME
newvalue
Run Code Online (Sandbox Code Playgroud)
怎么了
$ echo $USERNAME
myusername
$ export USERNAME=newvalue
$ echo $USERNAME
myusername
Run Code Online (Sandbox Code Playgroud)
我尝试过的
sudo...;unset USERNAME。有用的笔记
操作系统:macOS Mojave 10.14
Direnv:https://github.com/direnv/direnv
我在用 zsh
发布之前我做了什么
我能够使用direnv(https://github.com/direnv/direnv)多次更改环境变量,并且一切运行良好。
我能够在中设置本地环境变量.envrc。然后,我遇到了这个问题...
解
https://unix.stackexchange.com/questions/483469/cannot-change-the-environment-variable
在zsh中,USERNAMEvar是神奇的。这不是正常的导出环境变量。从手册页:
USERNAME <S>
The username corresponding to the real user ID of the shell process. If you
have sufficient privileges, you may change the username (and also the user
ID and group ID) of the shell by assigning to this parameter. Also (assum-
ing sufficient privileges), you may start a single command under a different
username (and user ID and group ID) by `(USERNAME=username; command)'
Run Code Online (Sandbox Code Playgroud)
在bash和fish这样的其他shell中,这不是一个特殊的var,您可以像设置任何其他env var一样进行设置:
bash$ echo $USERNAME
bash$ export USERNAME=wtf
bash$ echo $USERNAME
wtf
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
150 次 |
| 最近记录: |