How to loop through a range of decimal numbers in bash?
NickName:izxle Ask DateTime:2015-06-11T06:49:18

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.

Copyright Notice:Content Author:「izxle」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30768644/how-to-loop-through-a-range-of-decimal-numbers-in-bash

Answers
Ole Tange 2015-06-22T09:48:06

\n I also tried $ for i in $(seq 3.0 4.5 0.1); do echo $i; done but nothing happens.\n\n\nThe order is wrong:\n\n$ for i in $(seq 3.0 0.1 4.5); do echo $i; done\n",


drpetermolnar 2015-06-10T23:00:47

If you're looking for a loop from 3.5 to 4.5 in 0.1 steps this would work\n\nfor x in {35..45}; do\n y=`bc <<< \"scale=1; $x/10\"`\n echo $y\ndone\n\n\nThe same with 0.01 steps\n\nfor x in {350..450}; do\n y=`bc <<< \"scale=2; $x/100\"`\n echo $y\ndone\n",


More about “How to loop through a range of decimal numbers in bash?” related questions

How to generate equally distributed random numbers in a range and with decimal places in bash?

How can I generate equally distributed random numbers in a range and with p.e, 2 or 5 decimal places in bash without to use AWK or bc ? Bash usually only supports whole numbers. However, numbers with

Show Detail

bash loop through list of numbers except given number

to loop through a continous list of numbers in bash I can do for s in $(seq 1 5);do echo ${s} done to loop through a continous list of numbers leaving a given number out in python I can do: l...

Show Detail

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, bu...

Show Detail

Read range of numbers into a for loop

So, I am building a bash script which iterates through folders named by numbers from 1 to 9. The script depends on getting the folder names by user input. My intention is to use a for loop using read

Show Detail

How to loop over a range of numbers or use seq with a for loop in bash?

I am using for loops in bash to loop over an array of IPs from file. There are around 38 IPs and in one file and I want to select any range of IP like for example I should be able to loop over if a...

Show Detail

Loop through a decimal sequence

I am writing a loop in VBA for excel, and I would like to loop through a sequence of decimal numbers, rather than integers. For example: For i = 1 To 10 'Do something Next i But rather than

Show Detail

How to write a decimal for loop in bash

How can I write a decimal for loop in bash I get an error like ((: upgradver=1.00: syntax error: invalid arithmetic operator (error token is ".00") I am trying something like upgradever=1.00 ne...

Show Detail

How to loop through dates using Bash?

I have such bash script: array=( '2015-01-01', '2015-01-02' ) for i in "${array[@]}" do python /home/user/executeJobs.py {i} &amp;&gt; /home/user/${i}.log done Now I want to

Show Detail

loop through a collection of range of numbers in one line powershell

I am trying to find a way to loop through a collection of range of numbers in PowerShell. I have tried below and it works foreach ($i in 1..3) { &quot;$i&quot; } foreach ($i in 1,2,3) { &q...

Show Detail

How can I expand a range in a string in bash?

In bash how can I expand the range in a string var so I can use it in a for loop ? num=9999999X num=`echo $num | sed 's/X/\{1..9\}/g'` echo $num # outputs 9999999{1..9} echo ${num} # outputs 999...

Show Detail