Cannot change the environment variable
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
|
show 3 more comments
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
This variable is readonly and you can change it by switching user
– Romeo Ninov
Nov 22 '18 at 15:26
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
Nov 22 '18 at 15:27
Do you seereadonly USERNAME
ordeclare -r USERNAME
anywhere? Either of those would mark a variable as read-only.
– telcoM
Nov 22 '18 at 15:29
1
This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
– Kusalananda
Nov 22 '18 at 15:38
2
what doestypeset -p USERNAME
say?
– mosvy
Nov 22 '18 at 15:38
|
show 3 more comments
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
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
edited Nov 22 '18 at 16:36
Riccardo Persiani
asked Nov 22 '18 at 15:17
Riccardo PersianiRiccardo Persiani
1235
1235
This variable is readonly and you can change it by switching user
– Romeo Ninov
Nov 22 '18 at 15:26
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
Nov 22 '18 at 15:27
Do you seereadonly USERNAME
ordeclare -r USERNAME
anywhere? Either of those would mark a variable as read-only.
– telcoM
Nov 22 '18 at 15:29
1
This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
– Kusalananda
Nov 22 '18 at 15:38
2
what doestypeset -p USERNAME
say?
– mosvy
Nov 22 '18 at 15:38
|
show 3 more comments
This variable is readonly and you can change it by switching user
– Romeo Ninov
Nov 22 '18 at 15:26
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
Nov 22 '18 at 15:27
Do you seereadonly USERNAME
ordeclare -r USERNAME
anywhere? Either of those would mark a variable as read-only.
– telcoM
Nov 22 '18 at 15:29
1
This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
– Kusalananda
Nov 22 '18 at 15:38
2
what doestypeset -p USERNAME
say?
– mosvy
Nov 22 '18 at 15:38
This variable is readonly and you can change it by switching user
– Romeo Ninov
Nov 22 '18 at 15:26
This variable is readonly and you can change it by switching user
– Romeo Ninov
Nov 22 '18 at 15:26
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
Nov 22 '18 at 15:27
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
Nov 22 '18 at 15:27
Do you see
readonly USERNAME
or declare -r USERNAME
anywhere? Either of those would mark a variable as read-only.– telcoM
Nov 22 '18 at 15:29
Do you see
readonly USERNAME
or declare -r USERNAME
anywhere? Either of those would mark a variable as read-only.– telcoM
Nov 22 '18 at 15:29
1
1
This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
– Kusalananda
Nov 22 '18 at 15:38
This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
– Kusalananda
Nov 22 '18 at 15:38
2
2
what does
typeset -p USERNAME
say?– mosvy
Nov 22 '18 at 15:38
what does
typeset -p USERNAME
say?– mosvy
Nov 22 '18 at 15:38
|
show 3 more comments
1 Answer
1
active
oldest
votes
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
Nov 22 '18 at 15:54
2
@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
Nov 22 '18 at 16:10
I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
Nov 22 '18 at 16:34
2
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
Nov 22 '18 at 17:50
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
Nov 22 '18 at 15:54
2
@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
Nov 22 '18 at 16:10
I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
Nov 22 '18 at 16:34
2
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
Nov 22 '18 at 17:50
add a comment |
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
Nov 22 '18 at 15:54
2
@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
Nov 22 '18 at 16:10
I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
Nov 22 '18 at 16:34
2
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
Nov 22 '18 at 17:50
add a comment |
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 Nov 22 '18 at 15:47
JdeBPJdeBP
34.5k469163
34.5k469163
Running as a superuser I am able to change the variable. Thank you
– Riccardo Persiani
Nov 22 '18 at 15:54
2
@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
Nov 22 '18 at 16:10
I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
Nov 22 '18 at 16:34
2
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
Nov 22 '18 at 17:50
add a comment |
Running as a superuser I am able to change the variable. Thank you
– Riccardo Persiani
Nov 22 '18 at 15:54
2
@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
Nov 22 '18 at 16:10
I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
Nov 22 '18 at 16:34
2
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
Nov 22 '18 at 17:50
Running as a superuser I am able to change the variable. Thank you
– Riccardo Persiani
Nov 22 '18 at 15:54
Running as a superuser I am able to change the variable. Thank you
– Riccardo Persiani
Nov 22 '18 at 15:54
2
2
@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
Nov 22 '18 at 16:10
@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
Nov 22 '18 at 16:10
I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
Nov 22 '18 at 16:34
I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
Nov 22 '18 at 16:34
2
2
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
Nov 22 '18 at 17:50
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
Nov 22 '18 at 17:50
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Nov 22 '18 at 15:26
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
Nov 22 '18 at 15:27
Do you see
readonly USERNAME
ordeclare -r USERNAME
anywhere? Either of those would mark a variable as read-only.– telcoM
Nov 22 '18 at 15:29
1
This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
– Kusalananda
Nov 22 '18 at 15:38
2
what does
typeset -p USERNAME
say?– mosvy
Nov 22 '18 at 15:38