Create an array with a sequence of numbers in bash

Complementing the main answer

In my case, seq was not the best choice.
To produce a sequence, you can also use the jot utility. However, this command has a more elaborated syntaxis.

# 1 2 3 4
jot - 1 4

# 3 evenly distributed numbers between 0 and 10
# 0 5 10
jot 3 0 10

# a b c ... z
jot -c - 97 122

Using seq you can say seq FIRST STEP LAST. In your case:

seq 0 0.1 2.5

Then it is a matter of storing these values in an array:

vals=($(seq 0 0.1 2.5))

You can then check the values with:

$ printf "%s\n" "${vals[@]}"
0,0
0,1
0,2
...
2,3
2,4
2,5

Yes, my locale is set to have commas instead of dots for decimals. This can be changed setting LC_NUMERIC="en_US.UTF-8".

By the way, brace expansion also allows to set an increment. The problem is that it has to be an integer:

$ echo {0..15..3}
0 3 6 9 12 15

Bash supports C style For loops:

$ for ((i=1;i<5;i+=1)); do echo "0.${i}" ; done
0.1
0.2
0.3
0.4

Tags:

Arrays

Bash