GTU OS Program - 6
6. Write a shell script which will generates first n fibonacci numbers like: 1, 1, 2, 3, 5, 13,…
Complete code of the program
- read -p "Enter the value of n (number): " n
- x=0
- y=1
- i=2
- echo "Fibonacci Series up to $n terms is : "
- echo "$x"
- echo "$y"
- while [ $i -lt $n ]
- do
- i=`expr $i + 1`
- z=`expr $x + $y`
- echo "$z"
- x=$y
- y=$z
- done
Interpreting the fibonacci.sh file and executing it in terminal
- tkanu025@hp:~/lab_solutions$ chmod +x fibonacci.sh
- tkanu025@hp:~/lab_solutions$ ./fibonacci.sh
Output
Comments