I`v wrote some script, and have unexpected end of file
echo off
if [$JAVA_HOME = ""]; then goto no_java_home fi
if [$SRV_HOME = ""]; then goto no_srv_home fi
echo Uses JAVA_HOME=$JAVA_HOME
echo Uses SRV_HOME=$SRV_HOME
export ACP=""
export ACP=$ACP;$JAVA_HOME/lib/tools.jar
export ACP=$ACP;$SRV_HOME/ant/lib/ant.jar
export ACP=$ACP;$SRV_HOME/ant/lib/ant-launcher.jar
export ACP=$ACP;$SRV_HOME/ant/lib/ant-nodeps.jar
export ACP=$ACP;$SRV_HOME/ant/lib/optional.jar
export ACP=$ACP;$SRV_HOME/ant/lib/ant-contrib-1.0b3.jar
$JAVA_HOME/bin/java -Xmx512m -classpath $ACP org.apache.tools.ant.Main -buildfile $SRV_HOME/ant/ant_script.xml %*
goto ends
no_srv_home:
clear
echo "You should set the TMX_HOME environment variable. For example: TMX_HOME=d:\MYSERVER"
goto ends
no_java_home:
clear
echo "You should set the JAVA_HOME environment variable"
goto ends
ends: echo "OK"
Where is my problem?
Your problem is that your script looks like a haphazard mix of bash and cmd syntax. Here's a bash script.
if [ "$JAVA_HOME" = "" ]; then
echo 1>&2 "$0: You need to set the JAVA_HOME variable, e.g.: export JAVA_HOME='c:/java'"
exit 2
fi
if [ "$SRV_HOME" = "" ]; then
echo 1>&2 "$0: You need to set the SRV_HOME variable, e.g.: export SRV_HOME='d:/myserver'"
exit 2
fi
echo "$0: Uses JAVA_HOME=$JAVA_HOME"
echo "$0: Uses SRV_HOME=$SRV_HOME"
ACP="$JAVA_HOME/lib/tools.jar"
for x in ant ant-launcher ant-nodeps optional ant-contrib-1.0b3; do
ACP="$ACP;$SRV_HOME/ant/lib/$x.jar"
done
"$JAVA_HOME/bin/java" -Xmx512m -classpath "$ACP" \
org.apache.tools.ant.Main \
-buildfile "$SRV_HOME/ant/ant_script.xml" \
"$@"
Here's a list of things I've corrected:
[ … ]
requires spaces on each side of the brackets (except with punctuation like ;
). $foo
) should be in double quotes (otherwise the shell will do strange things if the value of the variable contains certain special characters such as spaces). echo 1>&2 "this is an error message"
. (This would apply to a cmd script as well.) ACP
is an internal script variable, there is no need to export it into the environment. ;
is a special character, so it must be quoted when you want to use it in a string. %*
is bash's "$@"
. $0
in each error message. Goto, really?
Alter your if statements to add a semi-colon before fi
if [$JAVA_HOME = ""]; then goto no_java_home ; fi
for example.
Your shell is unable to distinguish between the no_java_home command and the fi command because they appeared on the same line without a semi-colon delimiter or anything else that would end a statement. You have the same problem on your lines with clear echo; as far as sh
is concerned echo here is used as an argument to clear and is not a separate command.
But please, rewrite this without using goto!
Like this:
if [$JAVA_HOME = ""] ; then
clear
echo "You should set the JAVA_HOME environment variable"
elif [$SRV_HOME = ""] ; then
clear
echo "You should set the TMX_HOME environment variable. For example: TMX_HOME=d:\MYSERVER"
else
echo Uses JAVA_HOME=$JAVA_HOME
echo Uses SRV_HOME=$SRV_HOME
export ACP=""
export ACP=$ACP;$JAVA_HOME/lib/tools.jar
export ACP=$ACP;$SRV_HOME/ant/lib/ant.jar
export ACP=$ACP;$SRV_HOME/ant/lib/ant-launcher.jar
export ACP=$ACP;$SRV_HOME/ant/lib/ant-nodeps.jar
export ACP=$ACP;$SRV_HOME/ant/lib/optional.jar
export ACP=$ACP;$SRV_HOME/ant/lib/ant-contrib-1.0b3.jar
$JAVA_HOME/bin/java -Xmx512m -classpath $ACP org.apache.tools.ant.Main -buildfile
$SRV_HOME/ant/ant_script.xml %*
fi
echo "OK"
If I rewrite the following lines differently, the unexpected end of file error goes off.
Original line:
if [$JAVA_HOME = ""]; then goto no_java_home fi
if [$SRV_HOME = ""]; then goto no_srv_home fi
Updated:
if [$JAVA_HOME = ""]; then
goto no_java_home
fi
if [$SRV_HOME = ""]; then
goto no_srv_home
fi
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.