如果布尔条件为假,如何突破循环

时间:2013-03-06 21:55:14

标签: bash if-statement command-line terminal while-loop

大家好我想解决的问题是while循环在这两种情况下都能正常工作,即使你输入了no而第二个问题echo你要继续进行如果我输入是,它会在两种情况下都突破< / p>

echo would you like to provide  more numbers: 
read des

while [ "$des"=="yes" ];  do

    echo provide a number please:
    read num
    let x=3num+$num
    echo $x

    echo would you like to carry on 
    read new

    if [ "$new"=='no' ]; then
        break
    fi
done

2 个答案:

答案 0 :(得分:3)

要完成字符串比较,请添加空格:

而不是

while [ "$des"=="yes" ];  do

while [ "$des" == "yes" ];  do

答案 1 :(得分:1)

试试这个:

if [“$ new”==“no”];然后