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
- 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
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)?