2014-12-05 20 views
-2

我试图创建一个简单的程序,允许用户添加他们想要的任意数量的数字,然后获取总数。但是我遇到了一些问题,我想用字符串比较。我不明白为什么我在bash中比较字符串时遇到问题

#!/bin/sh 

total=0 
decision="y" 
echo "please enter a number >" 
read number 
total=$(($total+$number)) 
while [[$decision == "y"]] 
do 
    echo "would you like to add another number? Type y for yes and n for no >" 
    read decision 
if [$decision == "y"] 
then 
    echo "please enter a number >" 
    read number 
    total=$(($total+$number)) 
else 
    echo "your total is:" 
fi 
done 
echo $total 

终端说我在第8行,[[$ decision ==“y”]]行有问题。

我的比较有什么不对?

+1

将代码粘贴到http://www.shellcheck.net/它包含许多错误。 – fedorqui 2014-12-05 10:54:53

回答

3

[[实际上是一个shell命令。因此,你需要一个空格后面。

+0

已将其排序它,谢谢! – Finlay 2014-12-05 10:59:44

相关问题