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