Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop through a range of decimal numbers in bash?

I'd like to generate a sequence of equally spaced decimal numbers.

For example, I want to echo all numbers between 3.0 and 4.5, with step 0.1. I tried $ for i {3.0..4.5..0.1}; do echo $i; done, but this gives an error.

I also tried $ for i in $(seq 3.0 4.5 0.1); do echo $i; done but nothing happens.

like image 689
izxle Avatar asked Jun 10 '15 22:06

izxle


1 Answers

I also tried $ for i in $(seq 3.0 4.5 0.1); do echo $i; done but nothing happens.

The order is wrong:

$ for i in $(seq 3.0 0.1 4.5); do echo $i; done
like image 158
Ole Tange Avatar answered Oct 17 '22 22:10

Ole Tange