Re: safe way to set a path
Previously Michael A. Miller wrote:
> # A function to add to PATH. If it is already there, don't bother...
> add_to_path () {
> if [ -d $1 ]; then
> if [ ! `echo $PATH | grep $1` ]; then
That is wrong, it fails if what you want to add is a subset of an
existing path. For example considering PATH includes /usr/local/usr/bin and
you want to add /usr/bin.
A better approach would be to set IFS to : and loop over the PATH entries
and see if one matches with the directory you want to add.
Wichert.
--
_________________________________________________________________
/ Nothing is fool-proof to a sufficiently talented fool \
| wichert@wiggy.net http://www.liacs.nl/~wichert/ |
| 1024D/2FA3BC2D 576E 100B 518D 2F16 36B0 2805 3CB8 9250 2FA3 BC2D |
Reply to: