Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Forcing expansion without explicit eval nor a subshell?



Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> writes:

> On Nov 5,  5:07pm, Lloyd Zusman wrote:
> }
> } I can't figure out how to do the nesting stuff using arrays, without
> } things getting rather complex.
>
> You do end up needing one array for each level of nesting.
>
> E.g.:
>
>     yumargs=( --disablerepo='${(e)^disablerepos}' )
>     disablerepos=( dag '${(e)^livnarepos' )
>     livnarepos=( livna{,-updates,-extras,-testing} )
>
>     yum ${(e)yumargs}
>
> This corresponds to your example
>
>     yum --disablerepo={dag,livna{,-updates,-extras,-testing}}
>
> The extra arrays are the price you pay for wanting to avoid defining
> e.g. $livnarepos until the last minute and also avoid eval.
>
> You might also ask yourself whether there's another way to get the end
> result that you want, such as writing a wrapper function around yum.

Thanks.

Well, after realizing that I have to use "eval" with brace expansion, I
went and wrote this wrapper function:

  function yum {
    eval /usr/bin/yum ${yumargs:-} '"$@"'
  }

... and I have these variables set:

  livna='livna{,-testing,-updates,-extras}'
  dag=dag
  dries=dries
  freshrpms=freshrpms
  newrpms=newrpms
  fedora='fedora-{core,extras}'

Then, I can do things like this:

  yumargs="--d={$dag,$livna}"  # --d is equivalent to --disablerepo
  yum update

This lets me change yumargs based on the availability of the
repositories, and then just issue normal "yum" commands.

And now I see how I can do pretty much the same thing with arrays.

Thanks again.


-- 
 Lloyd Zusman
 ljz@xxxxxxxxxx
 God bless you.



Messages sorted by: Reverse Date, Date, Thread, Author