Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Reverse the order of an array?
- X-seq: zsh-users 4668
- From: Steve Talley <stephen.talley@xxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: Reverse the order of an array?
- Date: Fri, 8 Feb 2002 16:55:36 -0700
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <Pine.BSF.4.40.0202082239301.90676-100000@xxxxxxxxxxxxxxxx>; from schaefer@xxxxxxxxxxxxxxxx on Fri, Feb 08, 2002 at 10:59:37PM +0000
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20020208153514.C10334@thpppt> <Pine.BSF.4.40.0202082239301.90676-100000@xxxxxxxxxxxxxxxx>
Thanks Bart. The best that I had come up with was:
indexes=({$#osvers..1})
tmp=('$osvers['$^indexes']')
osvers=${(e)tmp}
Do you see any way (other than skipping the whole thing :) to simplify
this?
Thanks,
Steve
Bart Schaefer wrote:
> On Fri, 8 Feb 2002, Steve Talley wrote:
>
> > How can I easily reverse the order of an array in zsh?
>
> Depends what you mean by "easily."
>
> > I was hoping that something like
> >
> > osvers=($osvers[{$#osvers..1}])
> >
> > would work, but no luck.
>
> Array "slices" in zsh only have start and end points, and are always in
> ascending order by numeric position in the array. So you can't do this
> purely with parameter expansion in the general case.
>
> This works:
>
> for ((i=$#osvers; i>0; --i)) { osvers[i*2]=($osvers[1]); shift osvers }
Messages sorted by:
Reverse Date,
Date,
Thread,
Author