known name (word)
The best way to find what provides a word
(provided that word is a valid name for an alias, function or command) is to use the option -a
to type
:
$ type -a echo
echo is a shell builtin
echo is /bin/echo
If a function and an alias are also defined, you may get a similar list to this:
$ type -a echo
echo is aliased to `echo "A new echo"'
echo is a function
echo ()
{
printf '%s\n' "A function echo" "$@"
}
echo is a shell builtin
echo is /bin/echo
The order in which they are printed is the priority order. In the list printed above: the alias will be executed first. If the alias is removed (unalias
), the function is executed. And so on and so forth.
Example:
$ echo "test"
A function echo
A new echo
test
Quoting usually bypass aliases:
$ \echo # or "e"cho, "echo", 'e'"ch"o, and many other variations.
A function echo
test
Which is equal to unsetting the alias:
$ unalias echo; echo test
A function echo
test
The function may be erassed with unset (option -f) :
$ unset -f echo
$ type -a echo
echo is a shell builtin
echo is /bin/echo
An alias could be turn off with enable:
$ enable -n echo
$ type -a echo
echo is /bin/echo
And an external (external to the shell) utility may be moved:
# mv /bin/echo /bin/echo-aside
# type -a echo
bash: type: echo: not found
A list of builtins
If the name of the builtin is not known, it could be listed.
In bash, there is an (maybe?) oddly named command called enable
(builtin
in ksh
).
Calling enable
with no option will print an enabled
list of builtins:
$ enable
enable .
enable :
enable [
enable alias
…
There are options to print all (-a
), only enabled (-p
or nothing), and special (as defined by Posix) builtins (-s
).
Removing the word enable and making it a one line list:
$ echo $(enable -s | cut -d" " -f2)
. : break continue eval exec exit export readonly return set shift source times trap unset
$ echo $(enable -p | cut -d" " -f2)
. : [ alias bg bind break builtin caller cd command compgen complete compopt continue declare dirs disown echo enable eval exec exit export false fc fg getopts hash help history jobs kill let local logout mapfile popd printf pushd pwd read readarray readonly return set shift shopt source suspend test times trap true type typeset ulimit umask unalias unset wait