Wang Zong'an
Wang Zong'an

Reputation: 1682

BASH: iterate over a list of floating numbers in decrement

What I want to do is something similar to the python codes beneath, while the variables start, end, and spacing could all be float numbers and start > end.

for i in numpy.arange(start, stop, step): 
    print i

Or,

for i in numpy.linspace(start, stop, num):
    print i 

I know awk is handy (see the second answer in the question).

num=$(awk "BEGIN{for(i=${start};i>=${stop};i-=${step})print i}")   
for n in $num 
do 
  Do Something With $n 
done 

But, how to realize the iteration over a list of floating numbers in decrement in Bash without using awk?

Thanks !

Upvotes: 0

Views: 708

Answers (1)

jyvet
jyvet

Reputation: 2191

You may use seq

seq [OPTION]... FIRST INCREMENT LAST

Upvotes: 3

Related Questions