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

Re: counting in "for" loops



Typing away merrily, I produced the daft words:
> I wanted:
> % print ${(A)_::={1..10}}
> which would nicely leave $_ with the values, but _ is a readonly
> variable.  *sigh*

The docs for [zshexpn(1)/PARAMETER EXPANSION/Parameter Expansion Flags]
state:
   A   Create an array parameter with ${...:=...} or ${...::=...}.
       Assignment is made before sorting or padding.

However, this also works:
% print ${(A):-{1..10}}
since the null variable is unset.  Undocumented feature?

Be careful not to use:
% print ${(A)-{1..10}}
though as this uses $- (shell flags) and seems to silently drop the (A)
and the {1..10} ... almost as if it parses - twice, once as a variable
and once as 'if not set' which is untrue.

Curious.

I'm also tempted to rewrite some of my initialisation files as:
: ${(A)path::=/bin /usr/bin /wherever/bin}
just to cheer myself up.  *grin*
-- 
--> Phil Pennock ; GAT d- s+:+ a22 C++(++++) UL++++/I+++/S+++/H+ P++@ L+++
E-@ W(+) N>++ o !K w--- O>+ M V !PS PE Y+ PGP+ t-- 5++ X+ R !tv b++>+++ DI+ D+
G+ e+ h* r y?



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