我的简单if / then / else bash脚本出了什么问题?
if [ "$C" = "dev" ];then
export PREFIX=/home/bubu
export SERVER=localhost:2112
elif [ "$C" = "test" ]
export PREFIX=/server/node
export SERVER=e.foo.com:44033
else
export PREFIX=/server/node
export SERVER=f.foo.com:44033
fi
./foo.sh: line 9: syntax error near unexpected token `else'
./foo.sh: line 9: `else'
答案 0 :(得分:4)
应该是:
elif [ "$C" = "test" ]; then
答案 1 :(得分:2)
我建议用一个案例陈述来修复它:
case "$C" in
dev) export PREFIX=/home/bubu SERVER=localhost:2112;;
test) export PREFIX=/server/node SERVER=e.foo.com:44033;;
*) export PREFIX=/server/node SERVER=f.foo.com:44033;;
esac
答案 2 :(得分:0)
在elif声明之后缺少“then”:
elif [ "$C" = "test" ]; then