[email protected] wrote on 03/13/2013 20:16:32:

> Subject: Re: [ast-users] ksh93v- read bug
> --------
> 
> 
> > ksh93v- 2013-02-22 does not honor -r with -d ''.
> > Exemple:
> > 
> > ## correct behaviour with delim='\n'
> > ## expected ouput is \ \n
> > $ printf '\\\n' | read -r
> > $ printf '%s\n' "$REPLY" | od -c
> > 0000000   \  \n
> > 0000002
> > 
> > ## incorrect behaviour with delim='\0'
> > ## expected output is \ \0
> > $ printf '\\\000' | read -r -d ''
> > $ printf '%s\000' "$REPLY" | od -c
> > 0000000  \0
> > 0000001
> > 
> > Philippe Bergheaud
> > 
> 
> The problem is not with read.  The problem is the REPLY terminates with 
the
> 0 bytes.
> 
> The following should work:
>    typeset -bZ2 var
>    printf '\\\000' | read -r -d '' var
>    print -n -v var |  od -c
> 
> typeset -b stores binary data.  $var expands to the uuencoded value.
>    print -v var
> for a binary variable, outputs the value of the variable.
> Also, printf "%B" will output the contents without expanding it.
> 
> 
> David Korn
> [email protected]

David, let me try to revive this thread before the next alpha release.

Your answer states that REPLY terminates with the 0 byte.  If I understand 
you well, when read -r -d '' is fed with '\' followed by '\0', then REPLY 
should contain '\'.  It is not the case: REPLY is empty -- this is the bug 
I am trying to describe.

$ printf '\\\000' | od -c
0000000   \  \0
0000002
$ printf '\\\000' | read -r -d ''; printf '%s' "$REPLY" | od -c
0000000

I think that this is incorrect, and that one should expect the following 
output instead:

$ printf '\\\000' | read -r -d ''; printf '%s' "$REPLY" | od -c
0000000   \
0000001

Let me explain my use case.  I would like to use read -r -d '' as an 
alternative to typeset -b.  Would read -r -d '' behave as I expect, then 
one could load the contents of a binary file in an array, without using 
binary variables.  Here is an example:

$ i=0; { while read -r -d '' A[i]; do ((i++)); done; } </bin/ls

The data in /bin/ls has been split on '\0', and the entries of the array A 
contain the '\0' terminated chunks of data.  This alternative to typeset 
-b works fine for any kind of input data, except for the single pattern 
'\' '\0', where '\' is lost.

Side note: ksh93v- crashes with Memory Fault on my Linux/Intel box when 
the following alternative syntax is used: 
$ i=0; { while read -r -d '' A[i++]; do true; done; } </bin/ls

Philippe

_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to