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

Re: Splitting on unquoted equals



On May 6,  8:28am, Jesper Nygards wrote:
}
} Is there a way to say "split on '=' but not within quotes", similar to the
} way (z) treats white space?

Not really.  (z) works because it "understands" shell syntax.  You are
asking for the shell to "understand" HTML syntax.  It does not.  You
have two choices:

(1) Write an actual HTML element parser, in shell script.  (Probably
easier to use Perl HTML::Parser or similar.)

(2) Approach the problem differently.  For example, if you first split
on double-quotes and spaces and then strip off trailing equal signs:

torch% print -l ${${=${(s'"')mystring}}%=}
<element
name
myelement
url
http://site.com/path/config?myname=user
>

Curious aside - this doesn't work:

torch% print -l ${(s:\":)string}    
<element name="myelement" url="http://site.com/path/config?myname=user";>

But you can't use an un-escaped quote mark there either:

torch% print -l ${(s:":)string}       
braceparam dquote> 

-- 
Barton E. Schaefer



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