$ ASDF=hello; a=0; a=$(( 70 - $(echo $ASDF | awk '{print length}') )); echo "$a $ASDF"$(for i in {1..$a}; do printf "."; done) 65 hello. $
Why doesn't it print: 65 hello.................................................................
What am i missing?
On 2 January 2011 22:27, S Mathias smathias1972@yahoo.com wrote:
$ ASDF=hello; a=0; a=$(( 70 - $(echo $ASDF | awk '{print length}') )); echo "$a $ASDF"$(for i in {1..$a}; do printf "."; done) 65 hello. Why doesn't it print: 65 hello.................................................................
Because {1..$a} doesn't output the sequence 1..65 like you think it should. Replacing it with `seq 1 $a` does.
What am i missing?
To be honest... the point of this list - elementary Bash programming isn't a matter for the Fedora Users list.
On Sun, 2011-01-02 at 14:27 -0800, S Mathias wrote:
$ ASDF=hello; a=0; a=$(( 70 - $(echo $ASDF | awk '{print length}') )); echo "$a $ASDF"$(for i in {1..$a}; do printf "."; done) 65 hello. $
Why doesn't it print: 65 hello.................................................................
What am i missing?
The expression {1..$a} is being quoted and treated as a string, instead of being evaluated. If you change the printf from:
printf "."
...to:
printf "[$i]"
...you'll see what's happening.
-Chris
On Sun, 2011-01-02 at 14:27 -0800, S Mathias wrote:
$ ASDF=hello; a=0; a=$(( 70 - $(echo $ASDF | awk '{print length}') )); echo "$a $ASDF"$(for i in {1..$a}; do printf "."; done) 65 hello. $ Why doesn't it print: 65 hello.................................................................
You wrote: for i in {1..$a} I think you mean: for ((i=1;i<$a;i++))
Cheers. ---------------------------------------------- Rodolfo Alcazar Portillo - nospaze@gmail.com otbits.blogspot.com / counter.li.org: #367962 ---------------------------------------------- "Früher oder später emulieren wir euch." - linux.de
Rodolfo Alcazar Portillo wrote:
On Sun, 2011-01-02 at 14:27 -0800, S Mathias wrote:
$ ASDF=hello; a=0; a=$(( 70 - $(echo $ASDF | awk '{print length}') )); echo "$a $ASDF"$(for i in {1..$a}; do printf "."; done) 65 hello. $ Why doesn't it print: 65 hello.................................................................
You wrote: for i in {1..$a} I think you mean: for ((i=1;i<$a;i++))
Right, but with
i=0
or
i<=$a
to have an accurate count ;-)