0

I have this code that works:

$ array=( {100..300..100} )
$ for k in ${array[@]} ; do echo $k ; done
100
200
300

I want to parametrize the start and end points (and also the increment, because why not?) I tried this:

$ low=100
$ high=300
$ incr=100
$ array=( {$low..$high..$incr} )

But it didn't work:

$ for k in ${array[@]} ; do echo $k ; done
{100..300..100}

What am I doing wrong?

cauthon14
  • 269
  • 1
  • 3
  • 14

1 Answers1

2

From bash manual:

A sequence expression takes the form {x..y[..incr]}, where x and y are either integers or single characters, and incr, an optional increment, is an integer.

So, parameter and variable expansion are not performed on x, y and incr. You should use seq:

arr=( $(seq $low $incr $high) )
oguz ismail
  • 1
  • 16
  • 47
  • 69