WHAT I WANT TO DO
$ echo $USERNAME
myusername
$ export USERNAME=newvalue
$ echo $USERNAME
newvalue
WHAT IS HAPPENING
$ echo $USERNAME
myusername
$ export USERNAME=newvalue
$ echo $USERNAME
myusername
WHAT I TRIED
sudo
...;unset USERNAME
.USEFUL NOTES
OS: macOS Mojave 10.14
Direnv: https://github.com/direnv/direnv
I am using zsh
WHAT I DID BEFORE THE ISSUE
I was able to change my environment variable several times using direnv
(https://github.com/direnv/direnv), and everything was working well.
I was able to set local env variables in .envrc
.
Then, I encountered this issue...
SOLUTION
https://unix.stackexchange.com/questions/483469/cannot-change-the-environment-variable
In zsh the USERNAME
var is magical. It is not a normal exported env var. From the man page:
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)'
In other shells, like bash and fish, this is not a special var and you can set it just like any other env var:
bash$ echo $USERNAME
bash$ export USERNAME=wtf
bash$ echo $USERNAME
wtf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With