I've been testing a minimal Fedora install. To check the path for interpreters like python or node, I normally use which
.
I notice which
isn't installed by default. I could add the package, but I wonder if there's a shell builtin that can be used to perform this common task.
I'm using bash 4.2.
You can use
type
, which is a Bash builtin:For documentation, see
help [t]ype
, which refers to thetype
section in thebash
man page.(
help type
prints the help pages for two builtins which start with the string "type", one of which is obsolete and completely unrelated to this.)You can use
type
orcommand -v
. The output oftype
is human readable; the output ofcommand -v
can be executed by Bash.Note that they are actually a little different.
type
andcommand
look up the hashed value of the command. That is to say, if you typecmd
,type cmd
orcommand -v cmd
will tell you exactly what will be run. They also work on aliases, Bash functions, and Bash builtins (althoughtype -p
will ignore these and only return true files).which
just does a search on the PATH. This is different because:which
, but executing that command will use the hashed value (you can force update the hash in Bash withhash -r
).Usually people really want
type
, notwhich
, at least for interactive use, as they use it to find out "where is this command coming from when I run it?" You should only usewhich
if you really want to do a PATH lookup.