开发者

can't seem to spot this error in BASH insists that there is a syntax error

can't find the error here. when i run this program 开发者_如何学运维BASH comes up with "[ : 17: unexpected operator" i've tried it with a parameter ending in .c and with one in .java but neither seems to work.

EXT=`echo $1 | cut -f2 -d"."`

if [ "$EXT" == "c" ]; then
    NAME=`echo $1 | cut -f1 -d"."`
    gcc -Wall -o "$NAME" "$1"   
elif [ "$EXT" == "java" ]; then
    NAME=`echo $1 | cut -f1 -d"."`
    gcj -c -g -O $1 && gcj --main="$NAME" -o "$NAME" "${NAME}.o"
else    
    echo "hm... I don't seem to know what to do with that"
fi


test (aka [) doesn't have an == operator. String equality is = instead. Yes, that's a little bit weird.

Also, case is nice for this:

case "$1" in
  *.java)
    # java stuff here
    ;;
  *.c)
    # c stuff here
    ;;
  *)
    # otherwise...
esac


change all

if [ "$EXT" == "c"/"java" ];

to

if [ "$EXT" = "c"/"java" ];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜