The Watanabe shell has three sorts of built-ins, described in detail in its manual. All of the built-in commands are also listed there, but one has to infer that something is a "regular" built-in command from the absence of any note saying that the command is a "special" or a "semi-special" built-in. Regular built-ins are unmarked.
printf
is one such "regular" built-in. In native mode it is always invoked, irrespective of whether there is an external command found by that name.
$ PATH=/usr/bin
$ printf
printf: this command requires an operand
$ type printf
printf: a regular built-in at /usr/bin/printf
$
$ PATH=/
$ printf
printf: this command requires an operand
$ type printf
printf: a regular built-in (not found in $PATH)
$
But when the posixly-correct
shell option is set it is only a built-in if the external command can be found on the PATH
.
$ set --posixly-correct
$
$ PATH=/usr/bin
$ printf
printf: this command requires an operand
$
$ PATH=/
$ printf
yash: no such command `printf'
$
This is actually conformant to what the Single Unix Specifiation says, and has said since at least 1997.
It differs from the Z shell, the 93 Korn shell, the Bourne Again shell, and the Debian Almquist shell, none of which either implement or document such behaviour for regular built-ins. The Z shell, for example, documents that regular built-ins are always found, before the step that searches PATH
. So too does the Debian Almquist shell. And that's what these shells all do, even if invoked as sh
with their turn-on-POSIX options.
% /bin/exec -a sh zsh -c "PATH=/ ; type printf ; printf"
printf is a shell builtin
zsh:printf:1: not enough arguments
% /bin/exec -a sh ksh93 -c "PATH=/ ; type printf ; printf"
printf is a shell builtin
Usage: printf [ options ] format [string ...]
% /bin/exec -a sh bash --posix -c "PATH=/ type printf ; printf"
printf is a shell builtin
printf: usage: printf [-v var] format [arguments]
% /bin/exec -a sh dash -c "PATH=/ ; type printf ; printf"
printf is a shell builtin
sh: 1: printf: usage: printf format [arg ...]
%
However, not running printf
when it is not on the PATH
is the behaviour of the PD Korn shell, the Heirloom Bourne shell, and the MirBSD Korn shell; because they do not have a printf
built-in in the first place. ☺
% /bin/exec -a sh `command -v ksh` -c "PATH=/ ; type printf ; printf"
printf not found
sh: printf: not found
% /bin/exec -a sh `command -v oksh` -c "PATH=/ ; type printf ; printf"
printf not found
sh: printf: not found
% /bin/exec -a sh `command -v jsh` -c "PATH=/ ; type printf ; printf"
printf not found
sh: printf: not found
% /bin/exec -a sh mksh -c "PATH=/ ; type printf ; printf"
printf not found
sh: printf: not found
% ksh -c "type printf ; printf"
printf is a tracked alias for /usr/bin/printf
usage: printf format [arguments ...]
% oksh -c "type printf ; printf"
printf is a tracked alias for /usr/bin/printf
usage: printf format [arguments ...]
% jsh -c "type printf ; printf"
printf is hashed (/usr/bin/printf)
usage: printf format [arguments ...]
% mksh -c "type printf ; printf"
printf is a tracked alias for /usr/bin/printf
usage: printf format [arguments ...]
$
PATH
in order for a regular built-in to be executed -- then please make your question about that. – Jan 23 '19 at 17:30