Reputation: 305
Getting error:
syntax error near unexpected token `elif'
`elif [ "$PROJECT_DIR" = "Automation" ] then'
I'm saving in Unix line format in Textpad++ so I'm not sure what the problem is...
#!/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
Upvotes: 1
Views: 69
Reputation: 263307
The problem is that you need a semicolon (or a newline) between the ]
and the then
.
[
is not part of the shell's syntax. It's a built-in command, equivalent to the test
command (except that [
requires a ]
as its last argument and test
doesn't).
(On the other hand, the keywords if
, then
, elif
, and fi
as well as the semicolon, are part of the shell's syntax.)
So if you write:
if [ "$PROJECT_DIR" = "Utility" ] then
the word then
is simply another argument to the [
command.
Changing each occurrence of ] then
to ] ; then
should fix the problem.
Upvotes: 1
Reputation: 77876
Try like this instead (Removed most of the code lines to keep the answer short). no need of last elif
condition elif [ "$PROJECT_DIR" = "Sync" ]
. It should just be an else
part as pointed below.
if [ "$PROJECT_DIR" = "Utility" ]
then
echo "$PROJECT_DIR: Compiling..."
elif [ "$PROJECT_DIR" = "Automation" ]
then
echo "$PROJECT_NAME: Compiling..."
else
echo "$PROJECT_DIR: Compiling..."
fi
Upvotes: 0