这个bash脚本给了我一个错误,我无法弄清楚原因

时间:2012-07-24 02:10:39

标签: bash

我在这里关注一些教程,每当我执行此操作时,我都会

Do you want to create a bukkit server on this computer? (Hint: answer YES or NO) > no
answered no
./test.sh: line 44: syntax error near unexpected token `else'
./test.sh: line 44: 'else'

这是脚本:

while true; do
    read -p "Do you want to create a bukkit server on this computer? (Hint: answer YES or NO) > " yn
    case $yn in
        [Yy]* ) echo answered yes; INSTALL="Y"; break;;
        [Nn]* ) echo answered no; break;;
        * ) echo "Please answer yes or no.";;
    esac
done

if [ -z "$INSTALL" ];
    echo "Yay!"
else
    echo "Sadface!"
fi

我是一个bash新手:/

2 个答案:

答案 0 :(得分:2)

条件之后您错过了then个关键字:

if [ -z "$INSTALL" ]; then
    echo "Yay!"
else
    echo "Sadface!"
fi

答案 1 :(得分:1)

then之后需要if

while true; do
read -p "Do you want to create a bukkit server on this computer? (Hint: answer YES or NO) > " yn
case $yn in
[Yy]* ) echo answered yes; INSTALL="Y"; break;;
[Nn]* ) echo answered no; break;;
* ) echo "Please answer yes or no.";;
esac
done

if [ -z "$INSTALL" ]; then
echo "Yay!"
else
echo "Sadface!"
fi