[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash expansion crap...



On Tue, Oct 02, 2007 at 02:22:41PM -0700, Andrew Sackville-West wrote:
> On Tue, Oct 02, 2007 at 01:57:44PM -0700, ss11223 wrote:
> > On Oct 2, 3:40 pm, Andrew Sackville-West <and...@farwestbilliards.com>
> > wrote:
> > > Hey folks, help me out with this...please
> > >
> > > andrew@basement:~$ for i in {1..3}; do echo $i; done
> > > 1
> > > 2
> > > 3
> > > andrew@basement:~$ TEST=3; for i in {1..$TEST}; do echo $i; done
> > > {1..3}
> > >
> > > in the first example, its obvious. In the second, $TEST gets replaced
> > > with 3, but then the {} doesn't get expanded. I'm sure I have to do
> > > some kind of wacky $({[ type thing, but I'm not able to grok it. any
> > > ideas?
> > >
> > > the purpose is to be able to easily update some loops in a script for
> > > different numbers of object to iterate over. obvious, I guess.
> > >
> > > A
> > >
> > >  signature.asc
> > > 1KDownload
> > 
> > This works for me, BASH can do arithmetic!
> > 
> >  TEST=3;  for (( i=1; i<=$TEST; i++)); do echo $i; done
> 
> okay, that's much better than Mike Bird's
> 
> for i in $(eval echo {1..$TEST}) 
> 
> in that it's much clearer, to my eye, what's happening.
> thanks

just to wrap up this whole thing... looks I was having trouble seeing
the forest for the one large tree right in front of me. I love how
that happens -- encounter a problem like trying to get this variable
to expand, spend a bit of time trying to suss out the problem of
getting that variable to expand when all around me were numerous
alternative ways to do the same thing. 

Someone give me some nails for my hammer here...

A

Attachment: signature.asc
Description: Digital signature


Reply to: