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 for why there's an external version of cd. – Gordon Davisson Dec 21 '21 at 21:55
  • 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

1 Answers1

0

In Fedora, the bash package provides a file /usr/bin/type

https://www.rpmfind.net/linux/RPM/fedora/devel/rawhide/x86_64/b/bash-5.2.21-2.fc40.x86_64.html

And since type is a builtin for bash, it's likely that this /usr/bin/type file is a symlink to bash.

  • 1
    It's a two-line script that invokes the type builtin of /usr/bin/sh. In any case, it cannot behave like the builtin type as it can't know about the aliases or functions you have defined or the executables that you have manually hashed or the builtins you have enabled or disabled. If run from a shell other than sh, it will also potentially give you misleading information about what command is builtin. – Stéphane Chazelas Jan 15 '24 at 06:51