Can a non-root (without sudo permissions) run the following command:

export PATH=/tml:$PATH

If so, how does it work?

I thought environment variables are read-only for non-root users, while shell variables can be modified freely.

  • "I thought environment variables are read-only," Why did you think that?
    – muru
    Sep 12 at 11:21
  • @muru for non-root users Sep 12 at 11:25
  • The question remains. What did you read or see that makes you think so?
    – muru
    Sep 12 at 11:53
  • To my understanding, environment variables (unlike shell variables) are global. Which means they apply to every process. This is very dangerous if any user can modify values there. Sep 12 at 12:39
  • 1
    Every process has a copy of environment variables inherited from its parent, and can modify its own set of environment variables and also the set of environment variables passed to child processes upon creation.
    – muru
    Sep 12 at 12:41

The output of the following commands should convince you that you can modify your environment variables.

$ grep PATH ~/.profile 
# set PATH so it includes user's private bin if it exists

$ ls -l ~/.profile
-rw-r--r-- 1 sudodus sudodus 632 dec 10  2010 /home/sudodus/.profile

In other words, you can not only modify these variables temporarily, but also make it persist by modifying your configuration file ~/.profile. You, as a regular user can do it.

The following command line shows system files, where the PATH is set or modified

sudo grep -r 'PATH=' /etc/*

You may want to get more details. See for example the following link,

Unix & Linux: Complete view of where the PATH variable is set in bash - particularly the answer by Gilles.

  • So any user can change environment variables GLOBALY? And it will apply on root as well? Seems like I'm missing something here. Sep 12 at 11:29
  • 1
    You can change your environment variables, but not for other users unless you have superuser permisisons (can use sudo).
    – sudodus
    Sep 12 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.