如何在bash中生成步骤n的范围? (生成一系列带增量的数字) [英] How to produce a range with step n in bash? (generate a sequence of numbers with increments)
本文介绍了如何在bash中生成步骤n的范围? (生成一系列带增量的数字)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在bash中迭代范围的方法是
The way to iterate over a range in bash is
for i in {0..10}; do echo $i; done
使用步骤迭代序列的语法是什么?说,我想在上面的例子中只得到偶数。
What would be the syntax for iterating over the sequence with a step? Say, I would like to get only even number in the above example.
推荐答案
我会做
for i in `seq 0 2 10`; do echo $i; done
(当然 seq 0 2 10
将自己生成相同的输出。)
(though of course seq 0 2 10
will produce the same output on its own).
注意 seq
允许浮点数(例如, seq .5 .25 3.5
)但是bash的大括号扩展只允许整数。
Note that seq
allows floating-point numbers (e.g., seq .5 .25 3.5
) but bash's brace expansion only allows integers.
这篇关于如何在bash中生成步骤n的范围? (生成一系列带增量的数字)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文