bash 脚本是否有某种“eof 处无换行符”规则?

bash 脚本是否有某种“eof 处无换行符”规则?

我有两个文件,一个 env 文件和一个 run 文件。当我将它们部署到 Ubuntu 服务器时,出现错误:

./start-admin: 第 10 行: 语法错误: 文件意外结束

如果我部署然后在文件末尾添加换行符,它将显示错误。如果我删除它,错误就会消失。如果我再次部署并且不添加换行符,它仍然显示错误,但如果我添加换行符,错误就会消失。什么可能导致这种情况?

以下是我的脚本:

环境:

if [ "x${WD}" == "x" ];  then echo "missing required conf \"\${WD}\"" >&2; exit -1; fi

export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64
export JAR_FILE="$WD/mfa-admin.jar"
export MYSQL_URL=url1
export MYSQL_USER=root
export MYSQL_PASSWORD=pwd
export DB_URL=url2
export DB_USER=user
export DB_PASSWORD=pwd2

export EMAIL_HOST=mail-inbox
export EMAIL_PORT=25
export EMAIL_PERMISSION=false
export FAKE_EMAIL=email
export ACTIVATION_URL=url

export BIND_HOST=0.0.0.0
export BIND_PORT=8282

开始:

WD=`dirname $0`;

JAVA_OPTS=""

if [ -r "$WD/admin.env.conf" ]; then
  . $WD/admin.env.conf
fi

# required stuff
if [ "x${JAVA_HOME}" == "x" ];                              then echo "missing required conf \"\${JAVA_HOME}\""                                                  >&2; exit -1; fi
if [ "x${JAR_FILE}" == "x" ];                               then echo "missing required conf \"\${JAR_FILE}\""                                                   >&2; exit -1; fi
if [ "x${MYSQL_URL}" == "x" ];                   then echo "missing required conf \"\${MYSQL_URL}\""        >&2; exit -1; fi
if [ "x${MYSQL_USER}" == "x" ];                  then echo "missing required conf \"\${MYSQL_USER}\""       >&2; exit -1; fi
if [ "x${MYSQL_PASSWORD}" == "x" ];              then echo "missing required conf \"\${MYSQL_PASSWORD}\""   >&2; exit -1; fi
if [ "x${DB_URL}" == "x" ];                      then echo "missing required conf \"\${DB_URL}\""                            >&2; exit -1; fi
if [ "x${DB_USER}" == "x" ];                     then echo "missing required conf \"\${DB_USER}\""                           >&2; exit -1; fi
if [ "x${DB_PASSWORD}" == "x" ];                 then echo "missing required conf \"\${DB_PASSWORD}\""                       >&2; exit -1; fi

if [ "x${EMAIL_HOST}" == "x" ];                  then echo "missing required conf \"\${EMAIL_HOST}\""                       >&2; exit -1; fi
if [ "x${EMAIL_PORT}" == "x" ];                  then echo "missing required conf \"\${EMAIL_PORT}\""                       >&2; exit -1; fi
if [ "x${EMAIL_PERMISSION}" == "x" ];            then echo "missing required conf \"\${EMAIL_PERMISSION}\""                 >&2; exit -1; fi
if [ "x${FAKE_EMAIL}" == "x" ];                  then echo "missing required conf \"\${FAKE_EMAIL}\""                       >&2; exit -1; fi
if [ "x${ACTIVATION_URL}" == "x" ];              then echo "missing required conf \"\${ACTIVATION_URL}\""                   >&2; exit -1; fi

if [ "x${BIND_HOST}" == "x" ];                    then echo "missing required conf \"\${BIND_HOST}\""                         >&2; exit -1; fi
if [ "x${BIND_PORT}" == "x" ];                    then echo "missing required conf \"\${BIND_PORT}\""                         >&2; exit -1; fi

JAVA_OPTS="${JAVA_OPTS} -Dmysql.URL=\"${MYSQL_URL}\" "
JAVA_OPTS="${JAVA_OPTS} -Dmysql.USER=\"${MYSQL_USER}\" "
JAVA_OPTS="${JAVA_OPTS} -Dmysql.PASSWORD=\"${MYSQL_PASSWORD}\" "
JAVA_OPTS="${JAVA_OPTS} -Ddb.URL=\"${DB_URL}\" "
JAVA_OPTS="${JAVA_OPTS} -Ddb.USER=\"${DB_USER}\" "
JAVA_OPTS="${JAVA_OPTS} -Ddb.PASSWORD=\"${DB_PASSWORD}\" "

JAVA_OPTS="${JAVA_OPTS} -DEMAIL_HOST=\"${EMAIL_HOST}\" "
JAVA_OPTS="${JAVA_OPTS} -DEMAIL_PORT=\"${EMAIL_PORT}\" "
JAVA_OPTS="${JAVA_OPTS} -DEMAIL_PERMISSION=\"${EMAIL_PERMISSION}\" "
JAVA_OPTS="${JAVA_OPTS} -DFAKE_EMAIL=\"${FAKE_EMAIL}\" "
JAVA_OPTS="${JAVA_OPTS} -DACTIVATION_URL=\"${ACTIVATION_URL}\" "

JAVA_OPTS="${JAVA_OPTS} -DBIND_HOST=\"${BIND_HOST}\" "
JAVA_OPTS="${JAVA_OPTS} -DBIND_PORT=\"${BIND_PORT}\" "

JAVA="$JAVA_HOME/bin/java"

eval \"$JAVA\" $JAVA_OPTS -cp "${WD}:${JAR_FILE}" VertxNode

答案1

当我收到此消息时,这是脚本中 、 、 或 字符串`'匹配的结果。"有时,如果 if/then/fi、do/while 或 case/esac 语句不匹配,也会发生这种情况。我会仔细检查你的脚本。

相关内容