Can a non-root modify environment variables?

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.

7

1 Answer

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 PATH=~/bin:"${PATH}"
PATH="$PATH:/usr/games"
$ 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.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like