Philip Guenther
2014-07-01 07:54:32 UTC
XCU 2.9.1.1 describes how the shell does command seach and execution. To
quote:
------
1. If the command name does not contain any <slash> characters, the first
successful step in the following sequence shall occur:
a. If the command name matches the name of a special built-in
utility, that special built-in utility shall be invoked.
b. If the command name matches the name of a function known to
this shell, the function shall be invoked as described in
Section 2.9.5. If the implementation has provided a standard
utility in the form of a function, it shall not be recognized
at this point. It shall be invoked in conjunction with the path
search in step 1.d.
c. If the command name matches the name of a utility listed in the
following table, that utility shall be invoked.
alias false jobs read wait
bg fc kill true
cd fg newgrp umask
command getopts pwd unalias
d. Otherwise, the command shall be searched for using the PATH
environment variable as described in XBD Chapter 8:
i. If the search is successful:
a. If the system has implemented the utility as a regular
built-in or as a shell function, it shall be invoked at this
point in the path search.
b. Otherwise, the shell executes the utility in a separate utility
environment (see Section 2.12) with actions equivalent to
calling the execl() function as defined in <...>
...
ii. If the search is unsuccessful, the command shall fail with an
exit status of 127 and the shell shall write an error message.
------
Okay, so consider a shell which has 'test' as a built-in. It's not
special, let's assume there's no function definition, and its not in the
list in 1.c, so the shell has to do a search of $PATH per 1.d.
Question 1)
Part 1.d.i.a. *doesn't* refer to the search finding the utility in any
particular directory, such as a directory in the PATH required for
standards compliance. So it doesn't matter if it found a completely
different version of the utility; it can/should still invoke the
(standard-behaving) built-in version. Is that correct?
Question 2)
Part 1.d.ii says that if you override PATH with one that doesn't
include (versions of) the standard utilties, then built-ins not listed
in part 1c must not be invoked by the shell. For example, assuming
$HOME/empty doesn't exist and can be created, then this:
mkdir $HOME/empty
( unset -f test; PATH=$HOME/empty; test -d $HOME/empty )
echo $?
must output "127". Is that correct?
Checking of a few systems (linux, solaris 10, Mac OSX) find they seem to
answer my questions 1 and 2 with "yes" and "no", respectively. That is,
they treat all built-ins like the list in 1c, skipping the $PATH search
completely and rendering part 1.d.i.a. superfluous.
(If it matter neither whether the path search is successful, nor what it
finds when it is successful, then the search is pointless.)
Can we delete part 1.d.i.a ?
Philip Guenther
quote:
------
1. If the command name does not contain any <slash> characters, the first
successful step in the following sequence shall occur:
a. If the command name matches the name of a special built-in
utility, that special built-in utility shall be invoked.
b. If the command name matches the name of a function known to
this shell, the function shall be invoked as described in
Section 2.9.5. If the implementation has provided a standard
utility in the form of a function, it shall not be recognized
at this point. It shall be invoked in conjunction with the path
search in step 1.d.
c. If the command name matches the name of a utility listed in the
following table, that utility shall be invoked.
alias false jobs read wait
bg fc kill true
cd fg newgrp umask
command getopts pwd unalias
d. Otherwise, the command shall be searched for using the PATH
environment variable as described in XBD Chapter 8:
i. If the search is successful:
a. If the system has implemented the utility as a regular
built-in or as a shell function, it shall be invoked at this
point in the path search.
b. Otherwise, the shell executes the utility in a separate utility
environment (see Section 2.12) with actions equivalent to
calling the execl() function as defined in <...>
...
ii. If the search is unsuccessful, the command shall fail with an
exit status of 127 and the shell shall write an error message.
------
Okay, so consider a shell which has 'test' as a built-in. It's not
special, let's assume there's no function definition, and its not in the
list in 1.c, so the shell has to do a search of $PATH per 1.d.
Question 1)
Part 1.d.i.a. *doesn't* refer to the search finding the utility in any
particular directory, such as a directory in the PATH required for
standards compliance. So it doesn't matter if it found a completely
different version of the utility; it can/should still invoke the
(standard-behaving) built-in version. Is that correct?
Question 2)
Part 1.d.ii says that if you override PATH with one that doesn't
include (versions of) the standard utilties, then built-ins not listed
in part 1c must not be invoked by the shell. For example, assuming
$HOME/empty doesn't exist and can be created, then this:
mkdir $HOME/empty
( unset -f test; PATH=$HOME/empty; test -d $HOME/empty )
echo $?
must output "127". Is that correct?
Checking of a few systems (linux, solaris 10, Mac OSX) find they seem to
answer my questions 1 and 2 with "yes" and "no", respectively. That is,
they treat all built-ins like the list in 1c, skipping the $PATH search
completely and rendering part 1.d.i.a. superfluous.
(If it matter neither whether the path search is successful, nor what it
finds when it is successful, then the search is pointless.)
Can we delete part 1.d.i.a ?
Philip Guenther