The model employed by the Single Unix Specification (a.k.a. IEEE 1003.1) is that whether a command is built into a shell is a mere optimization, and the behaviour (if invoked in a conformant manner) should be the same for a built-in version of a command as for an external version. (This is regular built-ins, that is. Special built-ins are another matter.) In particular, if the command is not found as an external in a PATH
search, the built-in version is not to be executed.
This is indeed what happens with one shell. You'll find that the Watanabe shell conforms to the SUS. In its posixly-correct
mode, if echo
is not on the path, the built-in echo
command in the Watanabe shell will not be executed.
But the 93 Korn, Debian Almquist, Z, and Bourne Again shells in their most conformant modes still all execute built-ins even if there is no corresponding executable on PATH
. That is what is happening here for you. The Bourne Again shell has a built-in echo
command, and several others besides. It is executing that, even though it has not found an external echo
command in a PATH
search.
(Note that there are quite a few ways to invoke echo
in a non-conformant manner, or at least in a manner where the result is unspecified: Using -n
; using a backslash in any argument; using -e
; using other things expecting them to be command options or end of options markers. These not only reveal whether it is a built-in echo
, but even to an extent reveal what shell is in use. Fortunately, you did not hit any of them. ☺)
Further reading
$PATH
!” Not really, you seem to have set it to a not wanted value. Since your PATH now contains$PATH
literally, you must have used single quotes ('
) instead of double quotes ("
):export PATH='$PATH:/home/jon/.local/bin'
, haven’t you? – Melebius Feb 05 '20 at 11:15