$PATH contains directories twice
Since f440e2db the $PATH
on my machine, as set by /etc/profile
, contains many common directory twice. Presently, the default $PATH
created by a /bin/sh
login shell (i.e. ash
) looks as follows:
$ env -i sh -l
$ echo $PATH
/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
As one can see /sbin
, /usr/sbin
, /bin
, and /usr/bin
are contained twice in $PATH
. This is due to the fact that busybox ash sets $PATH
to /sbin:/usr/sbin:/bin:/usr/bin
before sourcing /etc/profile
. Since commit f440e2db /etc/profile
then appends to $PATH
causing the entries already included by ash
itself to be listed twice in $PATH
. This seems weird and is also undesirable since these directories will be searched twice by execl
, execv
, execle
, et cetera.
If we really need to append to $PATH
one solution would be checking if a given directory is already part of $PATH
before appending it to $PATH
. This is what Arch Linux does for instance https://github.com/archlinux/svntogit-packages/blob/ed2da51a91162eaa0916dc3d9725fb2b574fb901/trunk/profile#L6-L20