What is the difference between the built in echo command and /bin/echo?

9,955

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.

Share:
9,955

Related videos on Youtube

Arcana
Author by

Arcana

Updated on September 18, 2022

Comments

  • Arcana
    Arcana over 1 year

    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
    Arcana over 9 years
    Thank you for the answer but why are there two echos? What is the difference between the built in and the binary?
  • michas
    michas over 9 years
    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.