If I execute the test
command in bash, test
(evaluates conditional expression) built-in utility is started:
$ type test
test is a shell builtin
$ type -a test
test is a shell builtin
test is /usr/local/bin/test
test is /usr/bin/test
$
However, as seen in output of type -a test
above, there is another test
in /usr/local/bin directory and yet another one in /usr/bin directory. How are executables ordered, i.e. are the built-in commands always preferred and then the rest of the commands depend on the directory order in $PATH variable? In addition, is it possible to change the order of the executables started, e.g. if I type in test
, then /usr/bin/test is started instead of bash-builtin test
?
Best Answer
Highest priority is bash alias, then special builtins (only in POSIX mode), then functions, then builtins, then a search in
$PATH
.To execute a builtin, use
builtin test
.To execute an external application, use an explicit path:
/bin/test
.To ignore functions and aliases, use
command test
.To bypass just alias, use
\test
or any other kind of expansion.It's possible to disable/enable a builtin with
enable test
.(Updated according to comments below)
(Fixed incorrect admin edit that bash has
disable
builtin - in fact, there is onlyenable
)