[MNG-7270] Switch to shell alternative to "which"

In some circumstances the init script calls `which`, which may or may not be
available on the host system. Instead, use `command -v`, which is nearly
equivalent. One area it differs is if the command being queried is defined as
a shell alias. To avoid that, call `unset -f command` to avoid the situation
where "command" has been re-defined as a shell function.

See here for more information on this approach:
<https://pubs.opengroup.org/onlinepubs/009695399/utilities/command.html>

Tested with bash, sh (bash invoked as sh), posh, dash, zsh and mksh.

This closes #556
This commit is contained in:
Jonathan Dowland 2021-09-29 11:29:35 +01:00 committed by Michael Osipov
parent 0080e84588
commit 8852b87412
1 changed files with 1 additions and 1 deletions

View File

@ -20,7 +20,7 @@ if [ -n "$JAVA_HOME" ] ; then
fi
fi
else
JAVACMD="`which java`"
JAVACMD="`\\unset -f command; \\command -v java`"
if [ ! -x "$JAVACMD" ] ; then
echo "The java(1) command does not exist in PATH nor is JAVA_HOME set, so Apache Maven cannot be started." >&2