Re: sh(1): POSIX "Command Search and Execution"

Robert Elz <[email protected]>
Newsgroups gmane.os.netbsd.devel.userlevel
Message-ID <[email protected]>
    Date:        Sun, 22 Sep 2024 09:09:06 +0200
    From:        [email protected]
    Message-ID:  <[email protected]>

  | (whether your test about the first two chars, or the more restricting
  | but simplest first an alphanumeric),

On that point, my reasoning is that I can imaging having 2 sets of
(some perhaps) of the utilities, a basic set, and an enhanced set,
living in sub-directories (of say, /usr/bin).   One of those would
be in PATH as the default to use, but sometimes a user might want
to use the other version as a test of something.

Those could be named basic/ls basic/cat ... and enhanced/ls enhanced/cat
(etc), but that would then be a lot to type, so if it were me, the
subdir names would be '-' and '+', so I might have /usr/bin/+
in PATH, and then simply run
	-/cat file ...
to use the basic one.   Not allowing non-alphanumerics as the first
char would prohibit that kind of thing.

kre

ps: Of course, one can almost accomplish this with functions...

PATH_TO_BASIC_UTILITIES=/usr/bin/-
PATH_TO_ENHANCED_UTILITIES=/usr/bin/+
-() { ${PATH_TO_BASIC_UTILITIES}/"$@" ; }
+() { ${PATH_TO_ENHANCED_UTILITIES}/"$@" ; }

and then use them as
	- cat ...
	+ ls
instead of
	-/cat ...
	+/ls

and in that the "cat" part *is* allowed to have '/' in its name.

And if this wouldn't be good enough, then you also need to be
concerned with how functions like execlp() etc work.   What you're
proposing isn't really just a small(ish) change to sh, everything
that does path searches needs to understand it (system(3) ...).
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.