On Mon, 22 Sep 2025 10:43:27 -0400, Chet Ramey wrote:
> > > > +    for ((i=1; i<=n; i++)); do
> > > > +        "$@"
> > > 
> > > You need the eval, otherwise something like
> > > 
> > > repeat 5 v+=f
> > > 
> > > fails.
> > 
> > On the other hand, often you *don't* want the eval, because then
> > something like
> > 
> >      repeat 5 make CFLAGS="-g -O"
> > 
> > or
> > 
> >      file="name has spaces.txt"
> >      repeat 5 scp "$file" "$host:$dir/"
> > 
> > fails.
> 
> Yeah, that's the other side of using eval. You can quote your way out of
> this, but you can't evaluate a variable assignment without using eval.

With or without eval, or with any combination thereof, you still
won't be able to make a repeat function that covers all the bases.
For example, you won't be able to do this:

repeat { ((x++)); echo $x;}

Such a thing can only be done by a bash internal command, like...

time { ((x++)); echo $x;}

Which gives me a nice idea really: I'll try to patch time to take a `-n N'
option, i.e., run the pipeline N times before taking the final measurement.
But that's off-topic here. :-)

Thank you!


Reply via email to