Linux shell script practice (number and courtship, and seeking odd)

Linux shell script practice (number and courtship, and seeking odd)

For example: find and even-numbered 1-10; 1-10 and odd.

1, create qiuhe.sh script, run the script is written.
[root@localhost ~]# vim qiuhe.sh
#!/bin/bash
oushu=0
jishu=0
for ((n=0;n<=10;n+=2))
   do
    let oushu+=$n
done
   echo "1到10的偶数和为$oushu"


for ((n=1;n<10;n+=2))
   do
    let jishu+=$n
done
   echo "1到10的奇数和为$jishu"
2, run the script
[root@localhost ~]# bash qiuhe.sh
1到10的偶数和为30
1到10的奇数和为25
Published 43 original articles · won praise 56 · views 7920

Guess you like

Origin blog.csdn.net/weixin_42953006/article/details/103444767