2012-07-24 33 views
0

我在这里以下一些教程,每当我执行,我得到这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:/

+0

您可能还需要_explicitly_你的循环之前清楚'INSTALL'以防一些其他的代码已经设置。如果它被设置为_anything_并且你回答“否”,结果将不会是你所期望的。 – paxdiablo 2012-07-24 02:35:42

回答

2

你错过了病情后then关键字:

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

:D谢谢!我知道这将是一件愚蠢的事。 – 2012-07-24 02:33:30

1

你需要一个thenif

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 
相关问题