Skip to content

Commit

Permalink
[MNG-7270] Switch to shell alternative to "which"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jmtd authored and michael-o committed Oct 11, 2021
1 parent b6186e2 commit fb5f3f5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion apache-maven/src/bin/mvn
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ if $mingw ; then
fi

if [ -z "$JAVA_HOME" ] ; then
JAVACMD=`which java`
JAVACMD="`\\unset -f command; \\command -v java`"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
Expand Down

0 comments on commit fb5f3f5

Please sign in to comment.