This question already has an answer here:
I like to encapsulate commands within shell-functions using the same name. But to avoid the shell-function calling itself recursively, I specify the complete path of the command as the following example:
less()
{
test 0 -lt $# && echo -ne "\e]2;$@\a\e]1;$@\a" # Window title
/usr/bin/less -i -rS --LONG-PROMPT --shift 5 "$@"
}
But for some commands, I do not want to specify the path because it may change. I would prefer to use $PATH.
For instance, my following attempt failed to call mvn command using backslash: \mvn
mvn() # colorizes maven output
{
\mvn "$@" 2>&1 | #here: the shell-function recursively calls itself indefinitely
sed -u '
s/^\[ALL\].*/\o033[1;37m&\o033[0m/
s/^\[FATAL\].*/\o033[1;31m&\o033[0m/
s/^\[ERROR\].*/\o033[1;31m&\o033[0m/
s/^\[WARNING\].*/\o033[1;33m&\o033[0m/
s/^\[INFO\].*/\o033[1;37m&\o033[0m/
s/^\[DEBUG\].*/\o033[1;36m&\o033[0m/
s/^\[TRACE\].*/\o033[1;32m&\o033[0m/'
}
What is the best way to bypass this issue?
Please do not suggest to use a different shell-function name.
(I usually use bash but I am interested about other shell solutions.)
zshanswer, but applies forbashtoo: How can I create a function in zsh that calls an existing command with the same name?. – manatwork Feb 26 at 10:53