best way to ensure './' is at beginning of sys.path?

Dan Sommers dan at tombstonezero.net
Sat Feb 4 17:31:33 EST 2017


On Sat, 04 Feb 2017 21:19:06 +0200, Marko Rauhamaa wrote:

> Now, that's why the distros are careful to place $HOME/bin as the
> final entry of PATH; the system commands take precedence over the
> user's personal ones. However, the user is free to define the PATH any
> way they like.

I deliberately put $HOME/bin at the beginning of my path so that I can
override system commands.

> There's a school of thought that a script should never rely on PATH
> but it should spell out the complete path of every command it executes
> (including "mv", "cp", "rm" and the like) ...

It's usually sufficient to reset PATH at the top of a system script,
often just to /bin and /usr/bin (and maybe /sbin and /usr/sbin, although
the use case for /bin and /sbin has long since been overcome by events,
and the trend is towards eliminating them or simply making them symlinks
to /usr/bin and /usr/sbin).

> ... The problem with that approach is that different distros have core
> commands in different directories.

https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard takes care
of that (and, in fact, corroborates what I wrote about the possibility
of /bin and /sbin being symlinks).



More information about the Python-list mailing list