Is there a way to test whether a shell function exists that will work both for bash
and zsh
?
Bash – Test for function’s existence that can work on both bash and zsh
bashfunctionshell-scriptzsh
bashfunctionshell-scriptzsh
Is there a way to test whether a shell function exists that will work both for bash
and zsh
?
Best Answer
If you want to check that there's a currently defined (or at least potentially marked for autoloading) function by the name
foo
regardless of whether a builtin/executable/keyword/alias may also be available by that name, you could do:Though note that if there's a keyword or alias called
foo
as well, it would take precedence over the function (when not quoted).The above should work in
ksh
(where it comes from),zsh
andbash
.