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:
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).