Hello, I am a beginner to shell programming. Coded the following for Fibonacci series.
#!/bin/bash
fib() {
i=0
j=1
arr[0]=0
arr[1]=1
echo "enter the limit:"
read n
while [ $i -lt $n ]
do
fo= expr $j - 1
f1=$j
f2= expr $j + 1
arr[$f2]= expr ${arr[$f1]} + ${arr[$f0]}
echo ${arr[$f2]}
i= expr $i + 1
j= expr $j + 1
done
}
fib
The program is going into infinite loop. From debugging I understood that updated i,j
values are not being carried to next iteration of while
loop. Why is it so? Can someone please help.