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
On Sat, Sep 28, 2024 at 06:24:58PM +0700, Robert Elz wrote:
> 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?
Since I'm writing a pathsearch.7 to explain the PATH_SEARCH_OPT
option(s) for "qualified filenames" (searching in PATH for "dk/ctl",
"vect/in/dxf" etc.), Il will add your suggestion of expanding with a
colon only if defined. Neat.
Best,
--
Thierry Laronde <tlaronde +AT+ kergis +dot+ com>
http://www.kergis.com/
http://kertex.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89 250D 52B1 AE95 6006 F40C
Home |
Main Index |
Thread Index |
Old Index