In the example below I used awk to avoid a shell loop, but
you can certainly transcribe that to a shell construct...

compound x=( ...as posted below... )
print -v x | awk '/^\t[^\t]/ && sub(/=.*/,"")'


Janis

----------------------------------------
> Date: Tue, 22 Mar 2011 19:25:00 +0100
> Subject: Re: [ast-users] Enumerate member variable names in compound variable?
> From: [email protected]
> To: [email protected]
> CC: [email protected]
>
> David, your example doesn't work for nested compound variables, i.e.
> 'compound x=( a=1 b=2 c=3 compound d=( a=1 b=2 compund z=( y=3 )) )'.
> I tried it myself and did not found a simple way to extract just the
> names of the members of the top level and not any level below.
>
> Olga
>
> On Tue, Mar 22, 2011 at 7:17 PM, David Korn  wrote:
> > cc: [email protected]
> > Subject: Re: [ast-users] Enumerate member variable names in compound 
> > variable?
> > --------
> >
> >
> >> Developers, has any one found a way to enumerate the names of members
> >> in a compound variable, e.g. if I have compound var=( a=2 b=5
> >> c='hello' ) I like to have the list "a b c". How can I do that?
> >>
> >> Olga
> > You could write a function like the following:
> >>
> >
> > ===============cut here======================
> > function members
> > {
> > typeset nval
> > nameref var=$1
> > [[ ! -v var ]] && return 1
> > for nval in $(print -v var | grep =)
> > do print ${nval%%=*}
> > done
> > }
> >
> > compound var=( a=2 b=5 c='hello' )
> > members var
> > ===============cut here======================
> >
> > David Korn
> > [email protected]
> >
>
>
>
> --
> , _ _ ,
> { \/`o;====- Olga Kryzhanovska -====;o`\/ }
> .----'-/`-/ [email protected] \-`\-'----.
> `'-..-| / http://twitter.com/fleyta \ |-..-'`
> /\/\ Solaris/BSD//C/C++ programmer /\/\
> `--` `--`
> _______________________________________________
> ast-users mailing list
> [email protected]
> https://mailman.research.att.com/mailman/listinfo/ast-users
                                          
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to