Question: I am learning shell script. and i have this fibonacci sequence code. Can someone explain each line in the code to me and what it
I am learning shell script. and i have this fibonacci sequence code. Can someone explain each line in the code to me and what it does please?
| #!/bin/bash | |
| if [ $# -eq 1 ] | |
| then | |
| Num=$1 | |
| else | |
| echo -n "Enter a Number :" | |
| read Num | |
| fi | |
| f1=0 | |
| f2=1 | |
| echo "The Fibonacci sequence for the number $Num is : " | |
| for (( i=0;i<=Num;i++ )) | |
| do | |
| echo -n "$f1 " | |
| fn=$((f1+f2)) | |
| f1=$f2 | |
| f2=$fn | |
| done | |
| echo |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
