Shell Script To Generate Fibonacci Number

To generate Fibonacci number. In the Linux Bash shell script programming
Step by step program Algorithm For Generating Fibonacci Number
fibonacci()
{
choice=$1
n1=0
n2=1
i=1
while [ $i -le $choice ]
do
if [ $i -eq 1 ]
then
echo "$n1"
elif [ $i -eq 2 ]
then
echo "$n2"
else
new=`expr $n1 + $n2`
echo "$new"
n1=$n2
n2=$new
fi
i=`expr $i + 1`
done
echo "Enter the number of terms( 1-100 ) : "
read num
echo "Fibonacci Series for $num terms"
fibonacci $num
echo
Fibonacci Series Output Red Hat Rhel5
Enter the number of terms( 1-100 ) :10
Fibonacci Series for $num terms
0
1
1
2
3
5
8
13
21
34
CONCLUSION: The following shell script generates the Fibonacci series for a given range.

Related post