I was trying to make a recursive function that can calculate the Fibonacci of the enter number, by the way I got stuck on how to get the values obtained by the recursion.
<
I got stuck on how to get the values obtained by the recursion.
You already have it right in the last line of your script - $?
.
Just do the same in fib
- replace
term1=$(fib $number)
…
term2=$(fib $number)
with
fib $number; term1=$?
…
fib $number; term2=$?
Still your script returns strange values, but surely you can resume from here. (set -x
might help.)