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
























  • This variable is readonly and you can change it by switching user
    – Romeo Ninov
    Nov 22 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 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 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 at 15:38






  • 2




    what does typeset -p USERNAME say?
    – mosvy
    Nov 22 at 15:38















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
























  • This variable is readonly and you can change it by switching user
    – Romeo Ninov
    Nov 22 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 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 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 at 15:38






  • 2




    what does typeset -p USERNAME say?
    – mosvy
    Nov 22 at 15:38













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















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















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 16:36

























asked Nov 22 at 15:17









Riccardo Persiani

1235




1235












  • This variable is readonly and you can change it by switching user
    – Romeo Ninov
    Nov 22 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 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 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 at 15:38






  • 2




    what does typeset -p USERNAME say?
    – mosvy
    Nov 22 at 15:38


















  • This variable is readonly and you can change it by switching user
    – Romeo Ninov
    Nov 22 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 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 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 at 15:38






  • 2




    what does typeset -p USERNAME say?
    – mosvy
    Nov 22 at 15:38
















This variable is readonly and you can change it by switching user
– Romeo Ninov
Nov 22 at 15:26




This variable is readonly and you can change it by switching user
– Romeo Ninov
Nov 22 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 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 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 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 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 at 15:38




This is not a variable that is set by default on macOS. Are you setting it yourself somewhere?
– Kusalananda
Nov 22 at 15:38




2




2




what does typeset -p USERNAME say?
– mosvy
Nov 22 at 15:38




what does typeset -p USERNAME say?
– mosvy
Nov 22 at 15:38










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.






share|improve this answer





















  • Running as a superuser I am able to change the variable. Thank you
    – Riccardo Persiani
    Nov 22 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 at 16:10










  • I agree. However, I also can change it, simply switching from zsh to bash.
    – Riccardo Persiani
    Nov 22 at 16:34






  • 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 at 17:50











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


}
});














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






share|improve this answer





















  • Running as a superuser I am able to change the variable. Thank you
    – Riccardo Persiani
    Nov 22 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 at 16:10










  • I agree. However, I also can change it, simply switching from zsh to bash.
    – Riccardo Persiani
    Nov 22 at 16:34






  • 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 at 17:50















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.






share|improve this answer





















  • Running as a superuser I am able to change the variable. Thank you
    – Riccardo Persiani
    Nov 22 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 at 16:10










  • I agree. However, I also can change it, simply switching from zsh to bash.
    – Riccardo Persiani
    Nov 22 at 16:34






  • 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 at 17:50













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.






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 Nov 22 at 15:47









JdeBP

32.6k468153




32.6k468153












  • Running as a superuser I am able to change the variable. Thank you
    – Riccardo Persiani
    Nov 22 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 at 16:10










  • I agree. However, I also can change it, simply switching from zsh to bash.
    – Riccardo Persiani
    Nov 22 at 16:34






  • 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 at 17:50


















  • Running as a superuser I am able to change the variable. Thank you
    – Riccardo Persiani
    Nov 22 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 at 16:10










  • I agree. However, I also can change it, simply switching from zsh to bash.
    – Riccardo Persiani
    Nov 22 at 16:34






  • 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 at 17:50
















Running as a superuser I am able to change the variable. Thank you
– Riccardo Persiani
Nov 22 at 15:54






Running as a superuser I am able to change the variable. Thank you
– Riccardo Persiani
Nov 22 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 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 at 16:10












I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
Nov 22 at 16:34




I agree. However, I also can change it, simply switching from zsh to bash.
– Riccardo Persiani
Nov 22 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 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 at 17:50


















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


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




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

Bundesstraße 106

Verónica Boquete

Ida-Boy-Ed-Garten