One of the tenants of this case is:

>    In general, it's helpful for building administrative scripts as well as
>    test cases that there be some way to cause commands to issue output in
>    a format that is stable and *easy for scripts to parse*. 
It seems that it's so easy, that some of our "best and brightest" can't 
write to this specification.

Just a thought....   :-)

- jek3



John Leser wrote:
>
> It does work, the problem is your function d is using "set" to 
> separate the fields rather than "read":
>
> $ print ${.sh.version}
> Version M 1993-12-28 s+
> $ echo 'a\|b|c' | IFS="|" read v1;  print "v1=$v1"
> v1=a|b|c
> $ echo 'a\|b|c' | IFS="|" read v1 v2 v3; print "v1=$v1 v2=$v2 v3=$v3"
> v1=a|b v2=c v3=
>
> -John
>
> Nicolas Williams wrote:
>> On Wed, Jun 11, 2008 at 10:34:56PM -0400, Sebastien Roy wrote:
>>>         * Since it's possible that a field value could contain a 
>>> literal
>>>           "|", parseable output will escape literal "|" as "\|", and
>>>           literal "\" as "\\".  As it happens, this escape format is
>>>           already handled automatically by the "read" and "while read"
>>>           shell constructs, ensuring that parsing remains simple.
>>
>> % print ${.sh.version}
>> Version M 1993-12-28 s+
>> % function d {
>>     typeset OIFS=$IFS
>>     typeset IFS='|'
>>     read line
>>     set -- $line
>>     IFS=$OIFS
>>     for i in "$@"
>>     do
>>         print -r -- arg: "$i"
>>     done
>> }
>> % echo 'a\|b|c'
>> a\|b|c
>> % echo 'a\|b|c' | d
>> arg: a
>> arg: b
>> arg: c
>> % function d {
>>     typeset OIFS=$IFS
>>     typeset IFS='|'
>>     read -r line
>>     set -- $line
>>     IFS=$OIFS
>>     for i in "$@"
>>     do
>>         print -r -- arg: "$i"
>>     done
>> }
>> % echo 'a\|b|c' | d
>> arg: a\
>> arg: b
>> arg: c
>> %
>> Nico
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.opensolaris.org/pipermail/opensolaris-arc/attachments/20080613/f8ebc919/attachment.html>

Reply via email to