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.
Asked
Active
Viewed 454 times
0

dfsbbl
- 1
1 Answers
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.
-
1It'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 manuallyhash
ed or the builtins you have enabled or disabled. If run from a shell other thansh
, it will also potentially give you misleading information about what command is builtin. – Stéphane Chazelas Jan 15 '24 at 06:51
/usr/bin/type
a one line shell script that calls the builtin type? It would be very strange for an externaltype
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:49which
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 atype
executable, but see this question for why there's an external version ofcd
. – Gordon Davisson Dec 21 '21 at 21:55cd
external command? – ilkkachu Dec 21 '21 at 22:54read
too as an external binary? – ilkkachu Dec 21 '21 at 23:08/usr/bin/type
and/usr/bin/cd
and found that they are just executable bash scripts that call the built-intype
andcd
commands. I indeed also haveread
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 relatedcd
post. – dfsbbl Dec 22 '21 at 02:34cd
being a program. – Kamil Maciorowski Dec 22 '21 at 06:12