Assume I want to export a path, let's say FOOBAR
and make the changes not only effective immediately and everywhere but also permanent. My goal is to have a list of commands that can be entered manually in an active shell session as well as executed from within a shell script (which in turn might be executed via the shell or a GUI file manager etc.).
Old processes don't need to be aware of any changes.
Here's what I want to happen to FOOBAR
:
- Add a new value without overwriting previous values.
- Make the change accessible system-wide (for any program or shell session, no matter how it is launched) within the current user context.
- Make the change effective immediately (i.e. no logout required etc.)
My current approach is exporting the value as a set-command to both .profile
and .bashrc
:
echo "export FOOBAR=$FOOBAR:$HOME/example/" >> $HOME/.profile;
echo "export FOOBAR=$FOOBAR:$HOME/example/" >> $HOME/.bashrc;
source $HOME/.profile;
How can this be improved in terms of:
- It does work, but are there cases where this will fail and how can I avoid them (i.e. are there any common processes or actions a ubuntu user will make etc. that will break my exported path)?
- Are there any security concerns to this approach and how can those be fixed?
- Are there any other collisions or negative consequences I have to pay attention to, in order to make this as universal as possible (within the ubuntu family)?
/etc/bash.bashrc
and/etc/profile
. 2) " but are there cases where this will fail" . Which cases are we talking about ? Don't make people guess. Define your requirements clearly 3) " no logout required" part might not quite work for GUI, as gui sessions source~/.profile
on each login only once as far as i know, so they need to be restarted for change to take place – Sergiy Kolodyazhnyy Mar 17 '16 at 21:55FOOBAR
as variable. So that's a path variable used by another ( external ) command ? because there exists$PATH
variable , which is used by every shell and many programs – Sergiy Kolodyazhnyy Mar 17 '16 at 21:57