7

I was playing around with the type and which 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 as exit or type

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

Arcana
  • 103

1 Answers1

6

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.

michas
  • 21,510
  • Thank you for the answer but why are there two echos? What is the difference between the built in and the binary? – Arcana Oct 12 '14 at 22:30
  • Well, 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 and help echo. – michas Oct 12 '14 at 22:32