For user scripts, the usual advice is to append their directory to $PATH
in one's .profile
:
PATH="$PATH:$HOME/.myscripts" # or .bin or whatever
Apparently that is safer than prepending it: PATH="$HOME/.myscripts:$PATH"
But doing it the safe way means your script is going to be trumped by a system package with the same name. If you name your script mount
or import
, for example, unexpected things will happen when you try to use it.
I understand that many will see this as a feature, not a bug. But personally I want to be able to name my scripts whatever I like, including import
, and have them run without surprises.
As I understand it, the risks of prepending are:
- a malicious script could rewrite
ls
etc without having root access (but is this really a concern when installing software from standard distro repos only?) - a system package might call your user script instead of the other system package (but do user packages ever call
mount
or whatever without the full path, in practice? Seems like a bad idea)
How serious, exactly, are the security implications of prepending via .profile
on a single-user system?
ls
somewhere where the user has write access, it can probably just set an alias forls
or modifyPATH
too.mount
function will exist in your interactive shell session, and be used before anymount
command in the PATH, but the function will not interfere with a 3rd party script that invokesmount