I created it as a small story of Bash programming. This is the 5th bullet.
For more information on what the Fibonacci sequence is, click here [https://en.wikipedia.org/wiki/%E3%83%95%E3%82%A3%E3%83%9C%E3%83%8A% Please check E3% 83% 83% E3% 83% 81% E6% 95% B0).
Simply put, it is a sequence that can be created by adding the previous term and the previous term.
#!/bin/bash
m=0
n=1
echo -n "please input number => "
read num
if (( $num <= 1 || $num >= 2))
then
echo $m
echo $n
fi
(( num +=2 ))
for i in $(seq 1 $num)
do
(( o = $m + $n ))
echo $o
m=$n
n=$o
done
I think I can write more beautifully ...
$ ./fibonacci.sh
please input number => 8
0
1
1
2
3
5
8
13
21
34
55
89
By creating this program
--read command --Conditional expression --Conditional operator --Variables --Bash's manners
I understand.
Recommended Posts