0

I can't find the root cause of this script's error. Can anybody help me? Thanks in advance. Here is the whole script detail.

#!/bin/sh

CWD=`pwd`
LAUNCH_DIRECTORY=`eval dirname $0`
cd $LAUNCH_DIRECTORY
LAUNCH_DIRECTORY=`pwd`
cd $CWD

if [ -d "${LAUNCH_DIRECTORY}/java/bin" ]; then
  JAVA_HOME=${LAUNCH_DIRECTORY}/java
fi

if [ "${JAVA_HOME}" != "" ]; then
  PATH=${JAVA_HOME}/bin:${PATH}
fi

JAVA_VERSION=$(java -version 2>&1 | grep -i version | \
               cut -d'"' -f2 | cut -         d'.' -f2)

if [ -z "${JAVA_VERSION}" ] || [ "${JAVA_VERSION}" -lt 8 ]; then
  YAB_JAVA_OPTS="-XX:MaxPermSize=256m ${YAB_JAVA_OPTS}"
fi

export TERM=xterm

java ${YAB_JAVA_OPTS} \
     -Dlaunch.dir="${LAUNCH_DIRECTORY}" \
     -jar "${LAUNCH_DIRECTORY}/lib/yab-loader.jar" ${YAB_OPTS} ${1+"$@"}
agc
  • 7,973
  • 2
  • 29
  • 50
Unik Meng
  • 1
  • 1
  • I'm voting to close this question as off-topic because it does not indicate that you invested time & effort to solve the problem yourself. What did you try so far? Delta-debugging, for example? – Malte Schwerhoff Apr 14 '17 at 10:02
  • Replace `cut - d'.' -f2` with `cut -d'.' -f2` (remove tab or spaces before the `d`) – Walter A Apr 15 '17 at 17:39

1 Answers1

0
 if [ -z "${JAVA_VERSION}" ] || [ "${JAVA_VERSION}" -lt 8 ]; then

is not correct. Replace - for instance - by

if [ "${JAVA_VERSION:-0}" -lt 8 ]; then

Other possibility:

 if ( [ -z "${JAVA_VERSION}" ] || [ "${JAVA_VERSION}" -lt 8 ] ); then

Or like this:

 if [ -z "${JAVA_VERSION}" -o "${JAVA_VERSION}" -lt 8 ]; then

Or this:

 [ -z "${JAVA_VERSION}" ] || [ "${JAVA_VERSION}" -lt 8 ] && YAB_JAVA_OPTS="-XX:MaxPermSize=256m ${YAB_JAVA_OPTS}"

Reason: The "argument" to if must be a command. What you wrote, were two commands connected by ||.

Aside from this, a closing parenthisis is missing in the assignment of the variable JAVA_VERSION.

user1934428
  • 19,864
  • 7
  • 42
  • 87
  • Follow your comments: `if [ "${JAVA_VERSION:-0} -lt 8 ]; then` result >>> 0403-057 Syntax error at line 44 : `"' is not matched. `if ( [ -z "${JAVA_VERSION}" ] || [ "${JAVA_VERSION}" -lt 8 ] ); then` result >>> 0403-057 Syntax error at line 41 : `fi' is not expected. `if [ -z "${JAVA_VERSION}" -o "${JAVA_VERSION}" -lt 8 ]; then` result >>> -XX:MaxPermSize=256m : not found. 0403-057 Syntax error at line 41 : `fi' is not expected. – Unik Meng Apr 14 '17 at 08:58
  • The line where you set JAVA_VERSION is missing a closed parenthesis. – user1934428 Apr 14 '17 at 13:02
  • @user1934428 : Please add the missing quote in your answer, the line `if [ "${JAVA_VERSION:-0} -lt 8 ]; then`. – Walter A Apr 15 '17 at 17:32