Shell loops using non-integers?

bash, loops, scripting, sh

Solution

I find it surprising that in five years no one ever mentioned the utility created just for generating ranges, but, then again, it comes from BSD around 2005, and perhaps it wasn't even generally available on Linux at the time the question was made.

But here it is:

for i in $(seq 0 0.1 1)

Or, to print all numbers with the same width (by prepending or appending zeroes), use `-w`. That helps prevent numbers being sent as "integers", if that would cause issues.

The syntax is `seq [first [incr]] last`, with `first` defaulting to 1, and `incr` defaulting to either 1 or -1, depending on whether `last` is greater than or less than `first`. For other parameters, see seq(1).

Problem

I wrote a .sh file to compile and run a few programs for a homework assignment. I have a "for" loop in the script, but it won't work unless I use only integers: ``` #!/bin/bash for (( i=10; i<=100000; i+=100)) do ./hw3_2_2 $i done ``` The variable $i is an input for the program hw3_2_2, and I have non-integer values I'd like to use. How could I loop through running the code with a list of decimal numbers?

Original source