Bash manual says that brace expansion is performed before any other expansions.
I am writing a script which accepts two arguments:
#! /bin/bash
for b in {$1..$2}; do echo $b; done
I run it like:
$ ./myscript 0002 0010
{0002..0010}
The output isn't what I hope.
I hope to perform parameter expansion before brace expansion.
The expected output of my example is 0002 0003 0004 0005 0006 0007 0008 0009 0010
, not 2 3 4 5 6 7 8 9 10
. What would you replace {$1..$2}
with?
I hope that the solution works even when $1
and $2
are strings not just made of digits, but also made of letters and digits.
Note that the values $1
and $2
can only be given as arguments to the script. I think it is clear from the beginning, but point it out in case not.
seq $1 $2
?eval
? – Mikel Apr 22 '16 at 03:37