【发布时间】:2015-04-28 19:45:30
【问题描述】:
我必须将以下 shell 文件转换为批处理文件:
\#!/bin/bash
\#
\# Generates and compiles a lexer or parser and runs it (this means
\# that the lexer/parser must contain a main method)
\#
\# Example usage: antlr4-run.sh Lexer.g4
DIR="$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)"
ANTLR_JAR=$DIR/lib/antlr-4.2.2-complete.jar
BASENAME="${1%.*}"
OUTDIR=out
echo "Generating..."
java -jar $ANTLR_JAR $1 -o $OUTDIR || exit 1
echo "Compiling..."
(cd $OUTDIR; javac -cp .:$ANTLR_JAR ${BASENAME}*.java) || exit 1
\#\# run (try parser first, then lexer, then plain)
echo "Input (end with ^D):"
if [[ -a $OUTDIR/${BASENAME}Parser.class ]] ; then
(cd $OUTDIR; java -cp .:$ANTLR_JAR ${BASENAME}Parser) || exit 1
elif [[ -a $OUTDIR/${BASENAME}Lexer.class ]] ; then
(cd $OUTDIR; java -cp .:$ANTLR_JAR ${BASENAME}Lexer) || exit 1
elif [[ -a $OUTDIR/${BASENAME}.class ]] ; then
(cd $OUTDIR; java -cp .:$ANTLR_JAR ${BASENAME}) || exit 1
fi
exit 1
你能帮我举个例子吗?
DIR="$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)"
我知道我必须在批处理文件中使用 set Directory ="..." 定义一个变量,例如 $ 是 commandoline parameter... 但我不知道如何编写批处理文件中的行:/
【问题讨论】:
标签: java linux bash shell batch-file