Cannot change the environment variable
up vote
4
down vote
favorite
WHAT I AM USING
- zsh
- MacOS Mojave 14.10
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
Tried to set USERNAME
in .bashrc
, .zshrc
, .profile
and nothing changes...
Tried to unset
and reset and nothing changes...
osx zsh environment-variables
New contributor
|
show 3 more comments
up vote
4
down vote
favorite
WHAT I AM USING
- zsh
- MacOS Mojave 14.10
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
Tried to set USERNAME
in .bashrc
, .zshrc
, .profile
and nothing changes...
Tried to unset
and reset and nothing changes...
osx zsh environment-variables
New contributor
This variable is readonly and you can change it by switching user
– Romeo Ninov
yesterday
The weird thing is I am quite sure that I was able to change it, then I had probably messed up with something..
– Riccardo Persiani
yesterday
Do you seereadonly USERNAME
ordeclare -r USERNAME
anywhere? Either of those would mark a variable as read-only.
– telcoM
yesterday
1
This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
– Kusalananda
yesterday
2
what doestypeset -p USERNAME
say?
– mosvy
yesterday
|
show 3 more comments
up vote
4
down vote
favorite
up vote
4
down vote
favorite
WHAT I AM USING
- zsh
- MacOS Mojave 14.10
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
Tried to set USERNAME
in .bashrc
, .zshrc
, .profile
and nothing changes...
Tried to unset
and reset and nothing changes...
osx zsh environment-variables
New contributor
WHAT I AM USING
- zsh
- MacOS Mojave 14.10
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
Tried to set USERNAME
in .bashrc
, .zshrc
, .profile
and nothing changes...
Tried to unset
and reset and nothing changes...
osx zsh environment-variables
osx zsh environment-variables
New contributor
New contributor
edited yesterday
New contributor
asked yesterday
Riccardo Persiani
1235
1235
New contributor
New contributor
This variable is readonly and you can change it by switching user
– Romeo Ninov
yesterday
The weird thing is I am quite sure that I was able to change it, then I had probably messed up with something..
– Riccardo Persiani
yesterday
Do you seereadonly USERNAME
ordeclare -r USERNAME
anywhere? Either of those would mark a variable as read-only.
– telcoM
yesterday
1
This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
– Kusalananda
yesterday
2
what doestypeset -p USERNAME
say?
– mosvy
yesterday
|
show 3 more comments
This variable is readonly and you can change it by switching user
– Romeo Ninov
yesterday
The weird thing is I am quite sure that I was able to change it, then I had probably messed up with something..
– Riccardo Persiani
yesterday
Do you seereadonly USERNAME
ordeclare -r USERNAME
anywhere? Either of those would mark a variable as read-only.
– telcoM
yesterday
1
This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
– Kusalananda
yesterday
2
what doestypeset -p USERNAME
say?
– mosvy
yesterday
This variable is readonly and you can change it by switching user
– Romeo Ninov
yesterday
This variable is readonly and you can change it by switching user
– Romeo Ninov
yesterday
The weird thing is I am quite sure that I was able to change it, then I had probably messed up with something..
– Riccardo Persiani
yesterday
The weird thing is I am quite sure that I was able to change it, then I had probably messed up with something..
– Riccardo Persiani
yesterday
Do you see
readonly USERNAME
or declare -r USERNAME
anywhere? Either of those would mark a variable as read-only.– telcoM
yesterday
Do you see
readonly USERNAME
or declare -r USERNAME
anywhere? Either of those would mark a variable as read-only.– telcoM
yesterday
1
1
This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
– Kusalananda
yesterday
This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
– Kusalananda
yesterday
2
2
what does
typeset -p USERNAME
say?– mosvy
yesterday
what does
typeset -p USERNAME
say?– mosvy
yesterday
|
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
12
down vote
accepted
The USERNAME
shell variable is special in the Z shell.
It is always the account name of the user ID of the shell process.
You won't observe the behaviour that you observed in the Almquist, Watanabe, Korn, or Bourne Again shells. This variable is just an ordinary shell variable, that starts out unset, as far as they are concerned. Here's the 93 Korn shell, for example:
$ echo $USERNAME
$ USERNAME=wibble
$ echo $USERNAME
wibble
$
In the Z shell it starts out as the account name of the UID of the shell process. An attempt to set it will attempt to change that UID. This of course fails if you are not the superuser and leaves the variable back as it was before.
If you had run the Z shell as the superuser, however, you would have seen both the USERNAME
shell variable and your shell process's user ID change.
root # echo $USERNAME
root
root # USERNAME=JdeBP
JdeBP %
Further reading
- Paul Falstad et al. (2015-12-02). "Parameters Set By The Shell". Z Shell Manual. 5.2.
Running as a superuser I am able to change the variable. Thank you
– Riccardo Persiani
yesterday
2
@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
yesterday
I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
yesterday
1
Note that there can be more than one user name for a user id,zsh
reports the one returned bygetpwuid()
so an arbitrary one (one could argue it should uselogname()
instead). Changing$USERNAME
does asetuid()
, but alsosetgid()
/setgroups()
with the groups mentioned in the user database as when you log in as that user name, that's different from setting$UID
or$EUID
for instance. So by doing aUSERNAME=$USERNAME
you might very well change the list of groups of the process if there are several usernames for the current uid with different group membership.
– Stéphane Chazelas
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
12
down vote
accepted
The USERNAME
shell variable is special in the Z shell.
It is always the account name of the user ID of the shell process.
You won't observe the behaviour that you observed in the Almquist, Watanabe, Korn, or Bourne Again shells. This variable is just an ordinary shell variable, that starts out unset, as far as they are concerned. Here's the 93 Korn shell, for example:
$ echo $USERNAME
$ USERNAME=wibble
$ echo $USERNAME
wibble
$
In the Z shell it starts out as the account name of the UID of the shell process. An attempt to set it will attempt to change that UID. This of course fails if you are not the superuser and leaves the variable back as it was before.
If you had run the Z shell as the superuser, however, you would have seen both the USERNAME
shell variable and your shell process's user ID change.
root # echo $USERNAME
root
root # USERNAME=JdeBP
JdeBP %
Further reading
- Paul Falstad et al. (2015-12-02). "Parameters Set By The Shell". Z Shell Manual. 5.2.
Running as a superuser I am able to change the variable. Thank you
– Riccardo Persiani
yesterday
2
@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
yesterday
I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
yesterday
1
Note that there can be more than one user name for a user id,zsh
reports the one returned bygetpwuid()
so an arbitrary one (one could argue it should uselogname()
instead). Changing$USERNAME
does asetuid()
, but alsosetgid()
/setgroups()
with the groups mentioned in the user database as when you log in as that user name, that's different from setting$UID
or$EUID
for instance. So by doing aUSERNAME=$USERNAME
you might very well change the list of groups of the process if there are several usernames for the current uid with different group membership.
– Stéphane Chazelas
yesterday
add a comment |
up vote
12
down vote
accepted
The USERNAME
shell variable is special in the Z shell.
It is always the account name of the user ID of the shell process.
You won't observe the behaviour that you observed in the Almquist, Watanabe, Korn, or Bourne Again shells. This variable is just an ordinary shell variable, that starts out unset, as far as they are concerned. Here's the 93 Korn shell, for example:
$ echo $USERNAME
$ USERNAME=wibble
$ echo $USERNAME
wibble
$
In the Z shell it starts out as the account name of the UID of the shell process. An attempt to set it will attempt to change that UID. This of course fails if you are not the superuser and leaves the variable back as it was before.
If you had run the Z shell as the superuser, however, you would have seen both the USERNAME
shell variable and your shell process's user ID change.
root # echo $USERNAME
root
root # USERNAME=JdeBP
JdeBP %
Further reading
- Paul Falstad et al. (2015-12-02). "Parameters Set By The Shell". Z Shell Manual. 5.2.
Running as a superuser I am able to change the variable. Thank you
– Riccardo Persiani
yesterday
2
@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
yesterday
I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
yesterday
1
Note that there can be more than one user name for a user id,zsh
reports the one returned bygetpwuid()
so an arbitrary one (one could argue it should uselogname()
instead). Changing$USERNAME
does asetuid()
, but alsosetgid()
/setgroups()
with the groups mentioned in the user database as when you log in as that user name, that's different from setting$UID
or$EUID
for instance. So by doing aUSERNAME=$USERNAME
you might very well change the list of groups of the process if there are several usernames for the current uid with different group membership.
– Stéphane Chazelas
yesterday
add a comment |
up vote
12
down vote
accepted
up vote
12
down vote
accepted
The USERNAME
shell variable is special in the Z shell.
It is always the account name of the user ID of the shell process.
You won't observe the behaviour that you observed in the Almquist, Watanabe, Korn, or Bourne Again shells. This variable is just an ordinary shell variable, that starts out unset, as far as they are concerned. Here's the 93 Korn shell, for example:
$ echo $USERNAME
$ USERNAME=wibble
$ echo $USERNAME
wibble
$
In the Z shell it starts out as the account name of the UID of the shell process. An attempt to set it will attempt to change that UID. This of course fails if you are not the superuser and leaves the variable back as it was before.
If you had run the Z shell as the superuser, however, you would have seen both the USERNAME
shell variable and your shell process's user ID change.
root # echo $USERNAME
root
root # USERNAME=JdeBP
JdeBP %
Further reading
- Paul Falstad et al. (2015-12-02). "Parameters Set By The Shell". Z Shell Manual. 5.2.
The USERNAME
shell variable is special in the Z shell.
It is always the account name of the user ID of the shell process.
You won't observe the behaviour that you observed in the Almquist, Watanabe, Korn, or Bourne Again shells. This variable is just an ordinary shell variable, that starts out unset, as far as they are concerned. Here's the 93 Korn shell, for example:
$ echo $USERNAME
$ USERNAME=wibble
$ echo $USERNAME
wibble
$
In the Z shell it starts out as the account name of the UID of the shell process. An attempt to set it will attempt to change that UID. This of course fails if you are not the superuser and leaves the variable back as it was before.
If you had run the Z shell as the superuser, however, you would have seen both the USERNAME
shell variable and your shell process's user ID change.
root # echo $USERNAME
root
root # USERNAME=JdeBP
JdeBP %
Further reading
- Paul Falstad et al. (2015-12-02). "Parameters Set By The Shell". Z Shell Manual. 5.2.
answered yesterday
JdeBP
31.7k467148
31.7k467148
Running as a superuser I am able to change the variable. Thank you
– Riccardo Persiani
yesterday
2
@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
yesterday
I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
yesterday
1
Note that there can be more than one user name for a user id,zsh
reports the one returned bygetpwuid()
so an arbitrary one (one could argue it should uselogname()
instead). Changing$USERNAME
does asetuid()
, but alsosetgid()
/setgroups()
with the groups mentioned in the user database as when you log in as that user name, that's different from setting$UID
or$EUID
for instance. So by doing aUSERNAME=$USERNAME
you might very well change the list of groups of the process if there are several usernames for the current uid with different group membership.
– Stéphane Chazelas
yesterday
add a comment |
Running as a superuser I am able to change the variable. Thank you
– Riccardo Persiani
yesterday
2
@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
yesterday
I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
yesterday
1
Note that there can be more than one user name for a user id,zsh
reports the one returned bygetpwuid()
so an arbitrary one (one could argue it should uselogname()
instead). Changing$USERNAME
does asetuid()
, but alsosetgid()
/setgroups()
with the groups mentioned in the user database as when you log in as that user name, that's different from setting$UID
or$EUID
for instance. So by doing aUSERNAME=$USERNAME
you might very well change the list of groups of the process if there are several usernames for the current uid with different group membership.
– Stéphane Chazelas
yesterday
Running as a superuser I am able to change the variable. Thank you
– Riccardo Persiani
yesterday
Running as a superuser I am able to change the variable. Thank you
– Riccardo Persiani
yesterday
2
2
@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
yesterday
@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
yesterday
I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
yesterday
I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
yesterday
1
1
Note that there can be more than one user name for a user id,
zsh
reports the one returned by getpwuid()
so an arbitrary one (one could argue it should use logname()
instead). Changing $USERNAME
does a setuid()
, but also setgid()
/setgroups()
with the groups mentioned in the user database as when you log in as that user name, that's different from setting $UID
or $EUID
for instance. So by doing a USERNAME=$USERNAME
you might very well change the list of groups of the process if there are several usernames for the current uid with different group membership.– Stéphane Chazelas
yesterday
Note that there can be more than one user name for a user id,
zsh
reports the one returned by getpwuid()
so an arbitrary one (one could argue it should use logname()
instead). Changing $USERNAME
does a setuid()
, but also setgid()
/setgroups()
with the groups mentioned in the user database as when you log in as that user name, that's different from setting $UID
or $EUID
for instance. So by doing a USERNAME=$USERNAME
you might very well change the list of groups of the process if there are several usernames for the current uid with different group membership.– Stéphane Chazelas
yesterday
add a comment |
Riccardo Persiani is a new contributor. Be nice, and check out our Code of Conduct.
Riccardo Persiani is a new contributor. Be nice, and check out our Code of Conduct.
Riccardo Persiani is a new contributor. Be nice, and check out our Code of Conduct.
Riccardo Persiani is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483469%2fcannot-change-the-environment-variable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This variable is readonly and you can change it by switching user
– Romeo Ninov
yesterday
The weird thing is I am quite sure that I was able to change it, then I had probably messed up with something..
– Riccardo Persiani
yesterday
Do you see
readonly USERNAME
ordeclare -r USERNAME
anywhere? Either of those would mark a variable as read-only.– telcoM
yesterday
1
This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
– Kusalananda
yesterday
2
what does
typeset -p USERNAME
say?– mosvy
yesterday