What is the difference between the built in echo command and /bin/echo?
There is a builtin echo
and a command echo
. Use type -a echo
to see all of them.
Because type
itself is a shell builtin it is able to know about other builtins.
And which
is only a usual command. Therefore it does not know which shell you are using and only tells you about commands on disk.
Usually type
is the correct command to tell you what happen if you type some word in your shell.
Related videos on Youtube
Arcana
Updated on September 18, 2022Comments
-
Arcana over 1 year
I was playing around with the
type
andwhich
commands and I discovered something strange.type
either returns the path or says that a command is a Bash built in.which
either returns the path or nothing for built ins such asexit
ortype
What is strange is that
type echo
says that echo is a built in as I expected.But
which echo
gives /bin/echo as the path to the echo executable. This doesn't seem to happen for any other built in commands.I am wondering what the different between the two is, which one Bash chooses to execute in scripts and on the command line, and what the story behind the two echos is.
My system is Ubuntu Desktop 12.04
-
Gilles 'SO- stop being evil' over 9 yearsRegarding the
echo
builtin, see Why is echo a shell built in command?. Regardingwhich
, see Why not use “which”? What to use then?
-
-
Arcana over 9 yearsThank you for the answer but why are there two echos? What is the difference between the built in and the binary?
-
michas over 9 yearsWell, the one is built in bash and the other is hanging around on disk. There might be slight differences. Have a look at
man 1 echo
andhelp echo
.