Sometimes I define a function that shadows an executable and tweaks its arguments or output. So the function has the same name as the executable, and I need a way how to run the executable from the function without calling the function recursively. For example, to automatically run the output of fossil diff
through colordiff
and less -R
I use:
function fossil () {
local EX=$(which fossil)
if [ -z "$EX" ] ; then
echo "Unable to find 'fossil' executable." >&2
return 1
fi
if [ -t 1 ] && [ "$1" == "diff" ] ; then
"$EX" "$@" | colordiff | less -R
return
fi
"$EX" "$@"
}
If I'd be sure about the location of the executable, the I could simply type /usr/bin/fossil
. Bash recognizes that /
means the command it's an executable, not a function. But since I don't know the exact location, I have to resort to calling which
and checking the result. Is there a simpler way?
Best Answer
Use the
command
shell builtin: