I was doing some examination of internal (shell builit-ins) and external commands, and I saw something that has me puzzled.
The echo command is both an internal command, as well as an external command (/usr/bin/echo).
Just for grins, I executed the following command:
$ strace echo hello
I was expecting to see output similar to: strace: Cannot find executable 'echo'. Instead, to my surprise, I saw that the external command (/usr/bin/echo) was used, along with all the wonderful system calls that were made.
Okay, for almost half a century, I've always known internal commands to have precendence over external commands. With that being the case (if that is in fact the case), why was the external 'echo' invoked??????
I'm still learning
commander @Trevor , you have dived into the multiverse of Dr Strace!
strace is not a shell so it cant interpret built in echo. It is made to look for an executable file and it did instead found /usr/bin/echo or /bin/echo:
If you want to trace the built in echo, you are hereby directed to trace the shell itself :
also, strace does not work with aliases or any function :
So I think it is clear why precedence was overruled , because we broke it when we told strace to do "strace echo hello" .
So, when you pass echo to strace, it searches your $PATH for a regular executable file named echo (e.g., /usr/bin/echo or /bin/echo). It finds one and so it runs it.
If it couldn't, it wouldn't .
and then you would have got that error : strace: Cannot find executable 'echo'
Over to you commander !
commander @Trevor , you have dived into the multiverse of Dr Strace!
strace is not a shell so it cant interpret built in echo. It is made to look for an executable file and it did instead found /usr/bin/echo or /bin/echo:
If you want to trace the built in echo, you are hereby directed to trace the shell itself :
also, strace does not work with aliases or any function :
So I think it is clear why precedence was overruled , because we broke it when we told strace to do "strace echo hello" .
So, when you pass echo to strace, it searches your $PATH for a regular executable file named echo (e.g., /usr/bin/echo or /bin/echo). It finds one and so it runs it.
If it couldn't, it wouldn't .
and then you would have got that error : strace: Cannot find executable 'echo'
Over to you commander !
I do love these deep waters!!!!
This is pure gold!!!
I'm even celebrating the use of the "type -a echo" command. I had "type echo" in my arsenal, but I can't say that I recall ever using the -a option. Pure gold!!!
I don't know if I would have ever tried to strace an alias or a function, but one thing is for sure, I absolutely won't bother, now that I'm been informed/warned!!!
Finally, that method of tracing the internal echo is truly a bonus! That's worth 2 gold bars all by itself!
Chetan, how much do I owe you for this one : - )
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.