bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

document that read built-in can't return zero-length string in the middl


From: ilya Basin
Subject: document that read built-in can't return zero-length string in the middle of input
Date: Thu, 11 Jan 2024 10:37:03 +0300
User-agent: Mozilla Thunderbird

Dear.
I needed to read 16 bytes from a binary file and tried to replace a hexdump 
call with read built-in. I expected that with "-N1" if a NUL character is 
encountered bash would assign an empty string, however there's no indication 
that a NUL character was there and it simply assigns the next non-NUL character 
to the variable.
Example:

    $ printf 'a\0c' | { LC_ALL=C; read -r -N1 a; read -r -N1 b; read -r -N1 c; 
echo "a=$a"; echo "b=$b"; echo "c=$c"; }
    
    Expected:
    a=a
    b=
    c=c
    
    Actual:
    a=a
    b=c
    c=

That's questionable, but fine with me. Yet I couldn't find this in the man 
page. Can we document it?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]