Sequences expansion and variable in bash -
i having problem builtin sequences (ie: not using seq) in bash when seq number variable. example, works , print me 1 2 3:
for in {1..3};do echo $i;done
but :
bash-3.2$ a=3;for in {1..$a};do echo $i;done
fail , print me {1..3} only
this works zsh , know have alternative make counter thing wondering if bug or brace expansion feature!
in bash, brace expansion performed before variable expansion. see shell expansions order.
$ a=7; echo {1..3} {4..$a} 1 2 3 {4..7}
if want use variable, use c-style for
loops in shawn's answer.
Comments
Post a Comment