获取错误:
syntax error near unexpected token `elif'
`elif [ "$PROJECT_DIR" = "Automation" ] then'
我在Textpad ++中保存了Unix行格式,所以我不确定问题是什么......
#!/bin/bash
....
if [ "$PROJECT_DIR" = "Utility" ] then
echo "$PROJECT_DIR: Compiling..."
javac -sourcepath $SOURCE -classpath $CLASSPATH -d $OUTPUT $SOURCE/*.java -deprecation
echo "$PROJECT_DIR: Compiling..."
javac -sourcepath $SOURCE -classpath $CLASSPATH -d $OUTPUT $SOURCE/*.java -deprecation
elif [ "$PROJECT_DIR" = "Automation" ] then
echo "$PROJECT_NAME: Compiling..."
javac -sourcepath $SOURCE -classpath $CLASSPATH -d $OUTPUT $SOURCE/*.java
elif [ "$PROJECT_DIR" = "Sync" ] then
echo "$PROJECT_DIR: Compiling..."
javac -sourcepath $SOURCE -classpath $CLASSPATH -d $OUTPUT $SOURCE/*.java -deprecation
echo "$PROJECT_DIR: Compiling..."
javac -sourcepath $SOURCE -classpath $CLASSPATH -d $OUTPUT $SOURCE/*.java -deprecation
echo "$PROJECT_DIR: Compiling..."
javac -sourcepath $SOURCE -classpath $CLASSPATH -d $OUTPUT $SOURCE/*.java -deprecation
fi
答案 0 :(得分:1)
问题是您需要在]
和then
之间使用分号(或换行符)。
[
不是shell语法的一部分。它是一个内置命令,相当于test
命令(除了[
需要]
作为其最后一个参数,而test
不是{0}}
(另一方面,关键字if
,then
,elif
和fi
以及分号是部分shell的语法。)
所以如果你写:
if [ "$PROJECT_DIR" = "Utility" ] then
单词then
只是[
命令的另一个参数。
将每次] then
更改为] ; then
都可以解决问题。
答案 1 :(得分:0)
尝试这样做(删除大部分代码行以保持答案简短)。不需要上次elif
条件elif [ "$PROJECT_DIR" = "Sync" ]
。它应该只是else
部分,如下所示。
if [ "$PROJECT_DIR" = "Utility" ]
then
echo "$PROJECT_DIR: Compiling..."
elif [ "$PROJECT_DIR" = "Automation" ]
then
echo "$PROJECT_NAME: Compiling..."
else
echo "$PROJECT_DIR: Compiling..."
fi