(a) write the series as shown below
[Email protected] ding1]# bash 5.sh
2/1
3/2
5/3
8/5
13/8
21/13
34/21
55/34
89/55
144/89
233/144
The shell code is as follows:
#!/bin/bash
>aa
>bb
Echo 1 2 | Xargs-n1 >AA
For i in ' seq 20 '
Do
A= ' Cat AA | Sed-n ' $i ' P '
b= ' Cat AA |tail-1 '
echo $ (($a + $b)) >>aa
c= ' Cat AA | Sed-n ' $ (($i + 1)) ' P '
echo $c/$a >>BB
Done
Cat BB
The calculation results are as follows, using awk to calculate
[[email protected] ding1]# bash 5.sh |awk-f '/' {A+=$1/$2;print A} '
2
3.5
5.16667
6.76667
8.39167
10.0071
11.6261
13.2437
14.8619
16.4799
18.098
19.716
21.334
22.9521
24.5701
26.1881
27.8062
29.4242
31.0422
32.6603
[Email protected] ding1]#
This article is from the "It Life" blog, so be sure to keep this source http://dingxue.blog.51cto.com/12290895/1970438
Shell finishing (36) = = = Read the rules and write the series