tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: PATH vs current dir and dir sure to be not existing
Date: Sat, 28 Sep 2024 10:33:55 +0200
From: <tlaronde%kergis.com@localhost>
Message-ID: <Zve_cyjTmZAq4fkF%kergis.com@localhost>
| This does mean that one user setting a PATH with variables:
|
| PATH="/bin:/usr/bin:$MYSCRIPTS:/usr/pkg/bin"
|
| if MYSCRIPTS is not defined, will end up including the current working
| dir in his PATH, while it was not the intention.
Yes. The expansion happens before the value is assigned to
the variable. There is no difference between that and explicitly
including ::
| The general rule of safety is doing:
| PATH="/bin:/usr/bin:${MYSCRIPTS:-/not/existing}:/usr/pkg/bin"
You could, but that would be wasteful.
Better would be:
PATH="/bin:/usr/bin:${MYSCRIPTS:+${MYSCRIPTS}:}/usr/pkg/bin"
or
PATH="/bin:/usr/bin${MYSCRIPTS:+:${MYSCRIPTS}}:/usr/pkg/bin"
whichever you prefer (they are essentially the same thing).
Why stick an entry in PATH that you intend not to be used?
kre
Home |
Main Index |
Thread Index |
Old Index