Bash Script - Fibonacci

后端 未结 6 1591
日久生厌
日久生厌 2021-01-24 11:05

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.

<
6条回答
  •  故里飘歌
    2021-01-24 11:16

    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.)

提交回复
热议问题