1

This code

echo {1..7}

prints 1 2 3 4 5 6 7.

But this code

t=7
echo {1..$t}

prints {1..7}.

How do I get {1..$t} to expand to 1 2 3 4 5 6 7?

oz1cz
  • 5,504
  • 6
  • 38
  • 58
  • See [the bash manual](http://www.gnu.org/software/bash/manual/bashref.html#Shell-Expansions) for the order of expansions. – glenn jackman Sep 22 '13 at 16:24

2 Answers2

6

You don't. Use e.g. seq for that, because brace expansion is performed before any other expansions and eval is evil :-)

$ a=5

$ seq 1 $a
1
2
3
4
5
Fredrik Pihl
  • 44,604
  • 7
  • 83
  • 130
1

Use eval(evaluate) in shell script.

eval echo {1..$t}
user1502952
  • 1,390
  • 4
  • 13
  • 27