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

Re: using parameter expansion sorting flags



Hi,

It works with o and n flags :

% a=( f.0009.Atop.pnm f.0010.Atop.pnm f.0011.Atop.pnm
 f.0012.Atop.pnm f.0009.Bbot.pnm f.0010.Bbot.pnm f.0011.Bbot.pnm)

% print -l $a
f.0009.Atop.pnm
f.0010.Atop.pnm
f.0011.Atop.pnm
f.0012.Atop.pnm
f.0009.Bbot.pnm
f.0010.Bbot.pnm
f.0011.Bbot.pnm

% print -l ${(on)a}
f.0009.Atop.pnm
f.0009.Bbot.pnm
f.0010.Atop.pnm
f.0010.Bbot.pnm
f.0011.Atop.pnm
f.0011.Bbot.pnm
f.0012.Atop.pnm

% print -l ${${(on)a}[2]}
f.0009.Bbot.pnm

% PNMFILES2=( ${(on)a} )
% print -l ${PNMFILES2[2]}
f.0009.Bbot.pnm

-- 
Anthony CHARLES

On Thu, Sep 22, 2011 at 01:46:20AM -0500, Rory Mulvaney wrote:
> Hello,
> 
> I have a few filenames that I put into an array with:
> 
> PNMFILES=( f.*.{Atop,Bbot}.pnm )
> 
> the ordered contents of this array become:
> 
> f.0009.Atop.pnm f.0010.Atop.pnm f.0011.Atop.pnm f.0012.Atop.pnm
> f.0009.Bbot.pnm f.0010.Bbot.pnm f.0011.Bbot.pnm
> 
> Now I can't figure out how to order them in an array, using the parameter
> expansion sorting flags n and o, as:
> 
> f.0009.Atop.pnm f.0009.Bbot.pnm f.0010.Atop.pnm f.0010.Bbot.pnm
> f.0011.Atop.pnm f.0011.Bbot.pnm f.0012.Atop.pnm
> 
> Also I'd like the resulting resorted array PNMFILES2 to be such that:
> 
> echo ${PNMFILES2[2]} 
> 
> yields:
> 
> f.0009.Bbot.pnm
> 
> rather than some single character.
> 
> Thanks and regards again,
> Rory



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