Skip to content

Commit fb5f3f5

Browse files
jmtdmichael-o
authored andcommitted
[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
1 parent b6186e2 commit fb5f3f5

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • apache-maven/src/bin

apache-maven/src/bin/mvn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ if $mingw ; then
9494
fi
9595

9696
if [ -z "$JAVA_HOME" ] ; then
97-
JAVACMD=`which java`
97+
JAVACMD="`\\unset -f command; \\command -v java`"
9898
else
9999
JAVACMD="$JAVA_HOME/bin/java"
100100
fi

0 commit comments

Comments
 (0)