Removing PATH=...%builtin... from sh

Jilles Tjoelker jilles at stack.nl
Sat Dec 25 20:35:13 UTC 2010


Most ash derivatives have an undocumented feature where the presence of
an entry "%builtin" in $PATH will cause builtins to be checked at that
point of the PATH search, rather than before looking at any directories
as documented in the man page (very old versions do document this
feature).

I would like to remove this feature from sh, as it complicates the code,
may violate expectations (for example, /usr/bin/alias is very close to a
forkbomb with PATH=/usr/bin:%builtin, only /usr/bin/builtin not being
another link saves it) and appears to be unused (all the %builtin google
code search finds is in some sort of ash source code).

The feature also has a bug in that it does not work properly if there is
a PATH assignment before 'type', 'command -v' or 'command -V' and
%builtin differs between the set and temporary paths. (This worked in
8.x for 'command'; 'type' ignores PATH assignment in 8.x.)

It is true that dash ignores %builtin for the special builtins and the
"regular builtins" that are found before PATH, using it only for the
other builtins. I could do the same but I think it is not useful enough.

See also
http://lists.freebsd.org/pipermail/svn-src-head/2010-November/022613.html

Which builtins this is about:
POSIX special builtins:
  : . break continue eval exec exit export readonly return set shift
  times trap unset
POSIX commands found before PATH (regular builtins):
  alias bg cd command false fc fg getopts jobs kill pwd read true
  umask unalias wait
Other POSIX utilities that must be builtins:
  hash type ulimit
Other POSIX utilities:
  [ echo printf test
Non-POSIX utilities that must be builtins:
  builtin bind chdir jobid local setvar
Undocumented builtins:
  exp let wordexp

And for completeness one command that should really be a builtin or
otherwise magic:
Missing POSIX commands found before PATH (regular builtins):
  newgrp

-- 
Jilles Tjoelker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sh-builtin-always-first.patch
Type: text/x-diff
Size: 3036 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20101225/aa5cf89b/sh-builtin-always-first.bin


More information about the freebsd-hackers mailing list