2013-02-06 73 views
0

我试图编写一个脚本来编译带有gentoos java-config的java文件,但我最终得到了一个错误 zsh:parse error:condition expected:“$ 1”告诉我这是什么意思,为什么它会在函数中的第16行报告。

function jComp() { 

local java_mods = "" 

if (($# == 0)); then 
    echo "using javac on .java in folder" 
    `javac *.java` 
    return 0 

elif [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then 
    echo "Usage: jComp [java modules] [file]" 
    echo 
    echo "Options:" 
    echo " -h, This help message." 
    echo "modules has to be in the (java-config -l) list" 
    echo 
    echo "Report bugs to <[email protected]>." 

    return 0 
fi 

if [[ "$(java-config -v)" == "" ]]; then 
    echo "This script depends on java-config" 
    return 1 
elif [[ "$1" =="-d" ]] || [[ "$1" == "--default"]]; then 
`javac -cp .:$(java-config -p junit-4) *.java` 
    if [[ $# == 2 ]]; then 
    `javac -c .:$(java-config -p junit-4) "$2"` 
    return 0 
    fi 
fi 


while (($# > 1)); do 
if [[ ! -f "$1" ]]; then 
    java_mods="$java_mods $1" 
    shift 
    continue 
fi 
done 

`javac -cp .:$(java-config $java_mods)` 

return 0 
} 

欢迎链接和评论。在此先感谢

回答

6

它看起来像你的代码试图将存储在参数$ 1到字符串-d一个字符串,但比较是双等号后缺少空间:

elif [[ "$1" =="-d" ]] || [[ "$1" == "--default"]]; then 
      ^

elif [[ "$1" == "-d" ]] || [[ "$1" == "--default"]]; then 

我的天堂” t尝试了代码,但是,请尝试让我知道它是否解决了它!

顺便说一句,它也像第二比较也将失败,因为双方括号结束之前缺乏空间:

elif [[ "$1" == "-d" ]] || [[ "$1" == "--default"]]; then 
               ^
elif [[ "$1" == "-d" ]] || [[ "$1" == "--default" ]]; then 
0

你所有的backticked命令看起来是错误的。你想运行这些命令,而不是将它们的输出作为一个命令来运行,对吧?如果是这样,请从javac调用中删除所有反引号。

然后在[[ "$1" =="-d" ]]中有一个缺失空间,使==成为一个单独的标记(另一个由leroyse指出)。

相关问题