1

In bash when I type

echo {0..10}

I get

0 1 2 3 4 5 6 7 8 9 10

How can I use a variable instead of the upper bound? When I try

a=4
echo {0..$a}

I get

{0..4}

How can I fix that so I get the same as the first example?

MikeSchem
  • 950
  • 2
  • 16
  • 29

2 Answers2

2

I have found that you can use eval

a=5
eval echo {0..$a}
Matt Clark
  • 27,671
  • 19
  • 68
  • 123
0

Figured it out.

echo $(seq 1 $a)
MikeSchem
  • 950
  • 2
  • 16
  • 29
  • 1
    The `echo` isn't necessary; you are capturing the standard output of `seq` just to write it back to standard output. Just use `seq 1 $a` by itself. – chepner Dec 16 '16 at 02:05
  • While this code snippet may solve the question, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations! – kayess Dec 16 '16 at 09:10