I want to make a for loop in bash with 0.02 as increments I tried
for ((i=4.00;i<5.42;i+=0.02))
do
commands
done
but it didn't work. I appreciate if you help me out.
I want to make a for loop in bash with 0.02 as increments I tried
but it didn't work. I appreciate if you help me out. |
||||
Reading the
and then we get this section
So it can be clearly seen that you cannot use a One solution may be simply to multiply all your loop components by 100, allowing for this where you later use them, like this:
|
|||||||||||||||||||||
|
Avoid loops in shells. If you want to do arithmetic, use
Or
Note that
If you add a
Note that by default (unless you modify the output format with If you do really need to use a shell loop, because for instance you want to run specific commands for each iteration of that loop, either use a shell with floating point arithmetic support like Like:
Or:
unless you push the limits of your processor floating point numbers, If you don't have
That would work better for things like |
|||||||||||||||||||||
|
Use "seq" - print a sequence of numbers seq FIRST INCREMENT LAST
|
|||||
|
As others have suggested, you can use bc:
|
|||
|
bc
, but stopping on 4.52 might be tricky. use @roaima suggestion, have auxiliary var with step of 2, and usei=$(echo $tmp_var / 100 | bc)
– Archemar yesterday