bash shell script fibonacci not showing value 2 after 0 1 1?

后端 未结 2 526
无人共我
无人共我 2021-01-26 08:13

I am writing a bash script for fibonacci which is not printing the value after 0 1 1 . It is not printing \"2\" after 0 1 1. The code is given below.

echo \"ent         


        
相关标签:
2条回答
  • In bash, do not use the dollar sign on the left hand side of an assignment.

    $c=$a+$b

    should be

    c=$a+$b

    but it probably still does not do what you want, try

    c=$((a+b))
    

    instead.

    0 讨论(0)
  • 2021-01-26 09:09
    echo "enter the number"
    read n
    a=0
    b=1
    c=0
    while [ $b -le $n ]
    do
      c=`expr $a + $b`
      echo $c ' = ' $a ' + '  $b
      a=$b
      b=$c
    done
    
    0 讨论(0)
提交回复
热议问题