Updated on Apr 8, 2017, 5:47 PM IST: Minor edit that fixed the bug which had prevented the last number in the series from being printed.
#!/bin/bash
function fibo {
echo $1 # No 1
if [ $2 -gt $3 ] ;then # $3 = Max
return
fi
fibo $2 $(expr $1 + $2) $3
}
echo -n "Enter the upperlimit: "
read limit
fibo 0 1 $limit
Keywords (click to browse): fibonacci recursion function shell sh bash linux gnu unix script programming command-line