linux shell 动态生成 数组系列 seq使用技巧
?
如果对linux shell 数组不是很熟悉的话,请看上一篇文章:linux shell 数组建立及使用技巧? ,这篇文章主要讲是动态生成数组系列。方法应该很多,我这里主要以一个求和计算的题目为例进行分析。
?
题目:请用linux shell 写一段脚本,实现从1..1000中所有偶数的和值。
?
方法一:
通过while 循环得到需要的结果:
start=1;
total=0;
while [ $start -le 1000 ];do
??? [[ $(($start%2)) == 0 ]]&&total=$(($total+$start));
?? start=$(($start+1));
done;
echo $total;
?
<blockquote style="background-image: none; background-color: #f0f0f0; border-top-width: 1px; border-right-width: 2px; border-bottom-width: 2px; border-left-width: 1px; border-top-style: dotted; border-right-style: solid; border-bottom-style: solid; border-left-style: dotted; color: black; margin-left: