1

Is there a good program that can handle PATH updates and similar for Linux and Unix?

I would like an easier way to add and edit my PATH. Wouldn't it be nice if we could do it without logging out and in again.

I would like an easy way to echo $PATH, set and unset PATH variables.

I've written a shell script that just prints the path using a PAGER that defaults to less.

PAGER=more
if type less > /dev/null;then PAGER=less; fi
echo $PAGER
if [ -z ${1+x} ];then printenv|"$PAGER";else printenv|grep "$1"|"$PAGER"; fi

Now it would be nice if there already was a convenient way to edit a variable i.e. using $EDITOR to open and edit the path and please make it easy to propagate the change without forcing us to log out and login again.

  • The shell itself? What features you're after, what shall that program do? And are you talking about global, or user environment? Maybe even MultiUser? Your question definitely could use a few more details :) – Izzy Apr 7 '17 at 16:15
  • I'm guessing you're making changes to your .bashrc or .profile or .bash_profile. If you want these changes to take effect, you can just source them. After editing them, just run source .bashrc and it will run through that file again and the changes will be present in the session. – rovr138 Apr 8 '17 at 11:20
2

To change the environment variables the most usual tool is the default editor, (vi/emacs/whatever), applied to the .bashrc or other environment setting script that is run on login but you can, potentially also use tools such as sed or ex to make changes to such files.

To apply the changes without logging out and back in simply use the source command, (noting that it will only apply to the terminal session that it is invoked in and any new terminal sessions).

It is important to remember when doing this that if you wish to remove some environmental variable, rather than simply omit it you need to set VARNAME= rather than simply filtering it out so that it is not set.

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.