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...










share|improve this question









New contributor




Riccardo Persiani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • This variable is readonly and you can change it by switching user
    – Romeo Ninov
    13 hours ago










  • 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
    13 hours ago










  • Do you see readonly USERNAME or declare -r USERNAME anywhere? Either of those would mark a variable as read-only.
    – telcoM
    13 hours ago






  • 1




    This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
    – Kusalananda
    13 hours ago






  • 2




    what does typeset -p USERNAME say?
    – mosvy
    13 hours ago















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...










share|improve this question









New contributor




Riccardo Persiani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • This variable is readonly and you can change it by switching user
    – Romeo Ninov
    13 hours ago










  • 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
    13 hours ago










  • Do you see readonly USERNAME or declare -r USERNAME anywhere? Either of those would mark a variable as read-only.
    – telcoM
    13 hours ago






  • 1




    This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
    – Kusalananda
    13 hours ago






  • 2




    what does typeset -p USERNAME say?
    – mosvy
    13 hours ago













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...










share|improve this question









New contributor




Riccardo Persiani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question









New contributor




Riccardo Persiani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Riccardo Persiani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 12 hours ago





















New contributor




Riccardo Persiani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 13 hours ago









Riccardo Persiani

1235




1235




New contributor




Riccardo Persiani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Riccardo Persiani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Riccardo Persiani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • This variable is readonly and you can change it by switching user
    – Romeo Ninov
    13 hours ago










  • 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
    13 hours ago










  • Do you see readonly USERNAME or declare -r USERNAME anywhere? Either of those would mark a variable as read-only.
    – telcoM
    13 hours ago






  • 1




    This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
    – Kusalananda
    13 hours ago






  • 2




    what does typeset -p USERNAME say?
    – mosvy
    13 hours ago


















  • This variable is readonly and you can change it by switching user
    – Romeo Ninov
    13 hours ago










  • 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
    13 hours ago










  • Do you see readonly USERNAME or declare -r USERNAME anywhere? Either of those would mark a variable as read-only.
    – telcoM
    13 hours ago






  • 1




    This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
    – Kusalananda
    13 hours ago






  • 2




    what does typeset -p USERNAME say?
    – mosvy
    13 hours ago
















This variable is readonly and you can change it by switching user
– Romeo Ninov
13 hours ago




This variable is readonly and you can change it by switching user
– Romeo Ninov
13 hours ago












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
13 hours ago




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
13 hours ago












Do you see readonly USERNAME or declare -r USERNAME anywhere? Either of those would mark a variable as read-only.
– telcoM
13 hours ago




Do you see readonly USERNAME or declare -r USERNAME anywhere? Either of those would mark a variable as read-only.
– telcoM
13 hours ago




1




1




This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
– Kusalananda
13 hours ago




This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
– Kusalananda
13 hours ago




2




2




what does typeset -p USERNAME say?
– mosvy
13 hours ago




what does typeset -p USERNAME say?
– mosvy
13 hours ago










1 Answer
1






active

oldest

votes

















up vote
10
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.






share|improve this answer





















  • Running as a superuser I am able to change the variable. Thank you
    – Riccardo Persiani
    12 hours ago












  • @RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
    – Kusalananda
    12 hours ago










  • I agree. However, I also can change it, simply switching from zsh to bash.
    – Riccardo Persiani
    12 hours ago










  • 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
    10 hours ago











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',
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
});


}
});






Riccardo Persiani is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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








up vote
10
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.






share|improve this answer





















  • Running as a superuser I am able to change the variable. Thank you
    – Riccardo Persiani
    12 hours ago












  • @RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
    – Kusalananda
    12 hours ago










  • I agree. However, I also can change it, simply switching from zsh to bash.
    – Riccardo Persiani
    12 hours ago










  • 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
    10 hours ago















up vote
10
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.






share|improve this answer





















  • Running as a superuser I am able to change the variable. Thank you
    – Riccardo Persiani
    12 hours ago












  • @RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
    – Kusalananda
    12 hours ago










  • I agree. However, I also can change it, simply switching from zsh to bash.
    – Riccardo Persiani
    12 hours ago










  • 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
    10 hours ago













up vote
10
down vote



accepted







up vote
10
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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










answered 12 hours ago









JdeBP

31.7k467148




31.7k467148












  • Running as a superuser I am able to change the variable. Thank you
    – Riccardo Persiani
    12 hours ago












  • @RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
    – Kusalananda
    12 hours ago










  • I agree. However, I also can change it, simply switching from zsh to bash.
    – Riccardo Persiani
    12 hours ago










  • 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
    10 hours ago


















  • Running as a superuser I am able to change the variable. Thank you
    – Riccardo Persiani
    12 hours ago












  • @RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
    – Kusalananda
    12 hours ago










  • I agree. However, I also can change it, simply switching from zsh to bash.
    – Riccardo Persiani
    12 hours ago










  • 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
    10 hours ago
















Running as a superuser I am able to change the variable. Thank you
– Riccardo Persiani
12 hours ago






Running as a superuser I am able to change the variable. Thank you
– Riccardo Persiani
12 hours ago














@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
12 hours ago




@RiccardoPersiani Ummm... switching to root is not a "solution". Why do you need to change the value of this variable?
– Kusalananda
12 hours ago












I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
12 hours ago




I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
12 hours ago












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
10 hours ago




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
10 hours ago










Riccardo Persiani is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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





















































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







Popular posts from this blog

flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

Mangá

 ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕