0

I was reading an article on various Linux commands that can show location of programs in the search path, including which, type, and whereis. The article says that type is a built-in bash command, and when I run type type it indeed outputs "type is a shell builtin". However, when I run which type, instead of not output anything (which is the behavior in this AskUbuntu post), it outputs "/usr/bin/type". Is this different output of which caused by different distros since I uses Fedora instead of Ubuntu? In addition, why would there be a separate program called /usr/bin/type on my system, and what is the difference between it and the built-in bash command? In addition, I also noticed that there is a /usr/bin/cd program on my system while cd is also a built-in bash command. I also know the difference between the bash built-in time command and the /usr/bin/time program, but it seems that /usr/bin/type and built-in type command do almost the same thing on my system.

dfsbbl
  • 1
  • Is `/usr/bin/type` a one line shell script that calls the builtin type? It would be very strange for an external `type` command to be able to perfectly mimic a builtin version. For example you can define a function or alias in the shell that the external program would know nothing about. What you have installed on your machine is not only distro specific but also owner specific. – icarus Dec 21 '21 at 21:49
  • `which` is an external command, and so it doesn't know about shell things, like builtins, functions, and aliases. It *only* searches `$PATH` for executable files. I don't know why there's a `type` executable, but see [this question](https://unix.stackexchange.com/questions/50058/what-is-the-point-of-the-cd-external-command) for why there's an external version of `cd`. – Gordon Davisson Dec 21 '21 at 21:55
  • related: [What is the point of the `cd` external command?](https://unix.stackexchange.com/q/50058/170373) – ilkkachu Dec 21 '21 at 22:54
  • do you have `read` too as an external binary? – ilkkachu Dec 21 '21 at 23:08
  • Thanks for all the comments! After seeing all the suggestions I took a further look at the files `/usr/bin/type` and `/usr/bin/cd` and found that they are just executable bash scripts that call the built-in `type` and `cd` commands. I indeed also have `read` as an external bash script. Should I add an answer below to address this? I guess this is just specific to Fedora 35 and it may be related to POSIX requirements mentioned in the related `cd` post. – dfsbbl Dec 22 '21 at 02:34
  • [About POSIX and `cd` being a program](https://unix.stackexchange.com/a/38819/108618). – Kamil Maciorowski Dec 22 '21 at 06:12

0 Answers0