This question already has an answer here:
- Why is echo a shell built in command? 6 answers
(Note that this is entirely an academic question... I'm just curious about the answer, not trying to solve any particular problem.)
ECHO(1) manual page (GNU
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.
ECHO(1) manual page (BSD
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.
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.
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
rmdir, etc. make it into shells if the speed factor was important? Things like
rmdir whose implementation is almost literally a single call to a
libc function would seem to be obvious candidates for inclusion.