I have an issue with using command -p mkdir in a ksh93 shell script.
The command -p bit is supposed to, according to POSIX,
Perform the command search using a default value for
PATHthat is guaranteed to find all of the standard utilities.
The ksh93 manual has a similar wording:
The
-poption causes a default path to be searched rather than the one defined by the value ofPATH. Functions will not be searched for when finding name. In addition, if name refers to a special built-in, none of the special properties associated with the leading daggers will be honored. (For example, the predefined aliasredirect='command exec'prevents a script from terminating when an invalid redirection is given.)
I've boiled my script down to the following:
#!/usr/local/bin/ksh93 -x
echo "$PATH"
command -p mkdir t
Running it:
$ ./test.sh
+ echo /usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin
/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin
+ command -p mkdir t
./test.sh[3]: mkdir: not found [No such file or directory]
The default value of $PATH for ksh93 (according to its manual) is /bin:/usr/bin:, and mkdir is found in /bin:
$ command -v mkdir
/bin/mkdir
If I issue the getconf PATH command in the script (to get the value of the default system-defined $PATH), before calling mkdir, the call to mkdir succeeds.
This is seen in ksh93, "Version AJM 93u+ 2012-08-01", on at least Ubuntu, OpenBSD, macOS and Solaris, and also affect at least cat when invoked the same way.
The question: Did I miss something obvious here?
Additional info:
The builtin command in ksh93 lists a number of utilities under the (non-existent) path /opt/ast/bin. Does this have something to do with this?
$ builtin
:
.
[
/opt/ast/bin/basename
/opt/ast/bin/cat
/opt/ast/bin/chmod
/opt/ast/bin/cmp
/opt/ast/bin/cut
/opt/ast/bin/dirname
/opt/ast/bin/getconf
/opt/ast/bin/head
/opt/ast/bin/logname
/opt/ast/bin/mkdir
/opt/ast/bin/sync
/opt/ast/bin/uname
/opt/ast/bin/wc
alarm
alias
(etc.)
UPDATE: I have submitted this query to the ast-users mailing list as well.
#!ksh93script. – thrig Mar 01 '17 at 00:00-poption. – JdeBP Mar 01 '17 at 00:12/bin:/usr/bin:according to theksh93manual. Any more hints? – Kusalananda Mar 01 '17 at 07:40getconf PATHcommand? – glenn jackman Mar 01 '17 at 16:49/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin. My manual says "The default path is/bin:/usr/bin:", but it doesn't matter since/binis in both paths. – Kusalananda Mar 01 '17 at 16:54