Sujet : Re: Default PATH setting - reduce to something more sensible?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.unix.shellDate : 26. Jan 2025, 02:36:48
Autres entêtes
Organisation : None to speak of
Message-ID : <87msfebbkf.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5
User-Agent : Gnus/5.13 (Gnus v5.13)
cross@spitfire.i.gajendra.net (Dan Cross) writes:
In article <vn0bpf$29qe6$1@dont-email.me>,
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
[...]
if not a bug, looks like a Bad Design Idea if it's been done
deliberately. - YMMV.
>
It's obviously being done deliberately, and is easy to find in
the source code:
https://git.savannah.gnu.org/cgit/bash.git/tree/findcmd.c#n533
The code in question is:
xpath = (posixly_correct == 0 && *path == '~') ? bash_tilde_expand (path, 0) : path;
where `path` is an element of $PATH.
This is obviously deliberate, and I see similar code (without the
posixly_correct condition) in bash 1.05 from 1990.
According to Wikipedia, POSIX began in 1988, and the initial
release of bash was in 1989, just a year later. Obviously the
authors thought that expanding literal '~'s in $PATH was a good
idea at the time, and it's not suprising that they didn't pay much
attention to POSIX. It would have been nice if they'd documented it.
You may consider it bad design, and you're well within your
rights to do so, but opinions on that vary, and it doesn't mean
yours is correct.
As far as I can tell (I haven't investigated), all Bourne-based
shells other than Bash treat $PATH in the same way when executing
commands. Bash is the only shell I'm aware of that expands literal
'~' in $PATH.
The fact that it's not POSIX compliant behavior is at worst mildly
annoying. Bash correctly disables it in POSIX mode (enabled by the
--posix option, by running "set -o posix", by setting $POSIXLY_CORRECT
before starting bash, or by invoking it sas "sh").
I dislike the behavior because (a) it can quietly cause unexpected
problems (it's easy to miss the fact that $HOME is expanded within
double quotes and ~ is not), and (b) it's not documented. I certainly
consider it a misfeature. Whether it rises to the level of a bug is
a matter of opinion.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */