Janis, it looks this works:
ksh -c 'compound x=( a=1 typeset -a ar=( 8 9 10 ) b=2 i="( bello=hello
)" compound c=( typeset -a ar=( 1 2 3 ) d=6 e=9 ) ) ; print -v x' |
/usr/xpg4/bin/awk '/^\t[^\t]/ && sub(/=.*/,"")'
a
typeset -a ar
b
typeset -a c
i
Thank you.
Now I need some thing which does not use a pipe and awk. I will try
with ~(Ems) pattern (extended regular pattern, allowing matches for
newline in spans) and .sh.match
Olga
On Tue, Mar 22, 2011 at 8:00 PM, Janis Papanagnou
<[email protected]> wrote:
>
> 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
>
--
, _ _ ,
{ \/`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