* using parameter expansion sorting flags
@ 2011-09-22 6:46 Rory Mulvaney
2011-09-22 7:59 ` Anthony Charles
2011-09-22 8:32 ` Jérémie Roquet
0 siblings, 2 replies; 4+ messages in thread
From: Rory Mulvaney @ 2011-09-22 6:46 UTC (permalink / raw)
To: zsh-users
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: using parameter expansion sorting flags
2011-09-22 6:46 using parameter expansion sorting flags Rory Mulvaney
@ 2011-09-22 7:59 ` Anthony Charles
2011-09-22 12:23 ` Rory Mulvaney
2011-09-22 8:32 ` Jérémie Roquet
1 sibling, 1 reply; 4+ messages in thread
From: Anthony Charles @ 2011-09-22 7:59 UTC (permalink / raw)
To: zsh-users
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: using parameter expansion sorting flags
2011-09-22 7:59 ` Anthony Charles
@ 2011-09-22 12:23 ` Rory Mulvaney
0 siblings, 0 replies; 4+ messages in thread
From: Rory Mulvaney @ 2011-09-22 12:23 UTC (permalink / raw)
To: zsh-users
I see what I was doing wrong now - I had been assigning
PNMFILES2=${(o)PNMFILES} without the parentheses to indicate an array.
I forgot... Thanks!
On Thu, 22 Sep 2011, Anthony Charles wrote:
> 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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: using parameter expansion sorting flags
2011-09-22 6:46 using parameter expansion sorting flags Rory Mulvaney
2011-09-22 7:59 ` Anthony Charles
@ 2011-09-22 8:32 ` Jérémie Roquet
1 sibling, 0 replies; 4+ messages in thread
From: Jérémie Roquet @ 2011-09-22 8:32 UTC (permalink / raw)
To: Zsh Users; +Cc: Rory Mulvaney
Hi Rory,
2011/9/22 Rory Mulvaney <rorymulv@gmail.com>:
> 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
That's because you're mixing braces and globbing. What happens first is:
f.*.{Atop,Bbot}.pnm → f.*.Atop.pnm f.*.Btop.pnm
then only globbing is performed.
You could have used globbing only, and the “o” flag to have a sorted
array in the first place:
PNMFILES=( f.*.(Atop|Bbot).pnm(on) )
> 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.
PNMFILES2=${(on)PNMFILES}
Best regards,
--
Jérémie
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-09-22 12:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-22 6:46 using parameter expansion sorting flags Rory Mulvaney
2011-09-22 7:59 ` Anthony Charles
2011-09-22 12:23 ` Rory Mulvaney
2011-09-22 8:32 ` Jérémie Roquet
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).