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

More bash parameter syntax



`info bash` sayeth:

   Arrays are assigned to using compound assignments of the form
     name=(value1 ... valueN)
   where each VALUE is of the form `[[SUBSCRIPT]=]'STRING.  If the
   optional subscript is supplied, that index is assigned to; otherwise
   the index of the element assigned is the last index assigned to by the
   statement plus one.  Indexing starts at zero.  This syntax is also
   accepted by the `declare' builtin.

Thus:

   bash$ foo=([1]=bar [3]=baz [2]=flip [0]=flop)
   bash$ echo ${foo[@]}
   flop bar flip baz

I only wish this syntax didn't conflict with glob-pattern char classes.
It'd be nice to use for associative arrays:

   assoc=([barney]=betty [fred]=wilma [bambam]=pebbles)

instead of the currently-supported-if-you-have-the-right-patches

   typeset -A assoc
   assoc=(barney betty fred wilma bambam pebbles)

BTW, I have been noodling with the ${(kv)assoc[(i)pat]} code, and I have
[(i)pat] correctly searching the keys for pat rather than the values, but
I haven't worked out how to either get the (kv) information either into
or across getindex() (which parses everything inside the [ ] and then
derefs it).  Mainly I haven't decided how brave/inspired I feel to rework
the params.c code into a more flexible division of labor.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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