(Note that this is entirely an academic question... I'm just curious about the answer, not trying to solve any particular problem.)
From the ECHO(1)
manual page (GNU echo
):
NOTE: your shell may have its own version of echo, which usually supersedes the version described here. Please refer to your shell's documentation for details about the options it supports.
From the ECHO(1)
manual page (BSD echo
):
Some shells may provide a builtin echo command which is similar or identical to this utility. Most notably, the builtin echo in sh(1) does not accept the -n option. Consult the builtin(1) manual page.
When running echo
from the shell, an internal command is run, but specifying a full path e.g. /bin/echo
, the external program is run.
What's the justification for having the shell itself implement that particular command. There are definitely commands which must be implemented by the shell (e.g. cd
, read
, etc.) but why echo
? Is it because it's used so often, and the time-savings for avoiding process setups and context-switches is measurable -- especially historically?
Ignoring the fact that e.g. bash
has a huge number of not-strictly-necessary features, why didn't things like expr
, [
/test
, mkdir
, rmdir
, etc. make it into shells if the speed factor was important? Things like mkdir
and rmdir
whose implementation is almost literally a single call to a libc
function would seem to be obvious candidates for inclusion.
[
/test
did.