Re: document that read built-in can't return zero-length string in the middle of input

2024-01-15 Thread alex xmb sw ratchev
On Mon, Jan 15, 2024, 19:03 Chet Ramey wrote: > On 1/11/24 7:29 PM, Ángel wrote: > > On 2024-01-11 at 09:29 -0500, Chet Ramey wrote: > >> On 1/11/24 2:37 AM, ilya Basin wrote: > >>> Dear. > >>> I needed to read 16 bytes from a binary file and tried to replace a > >> hexdump call with read

Re: document that read built-in can't return zero-length string in the middle of input

2024-01-15 Thread Chet Ramey
On 1/11/24 7:29 PM, Ángel wrote: On 2024-01-11 at 09:29 -0500, Chet Ramey wrote: On 1/11/24 2:37 AM, ilya Basin wrote: 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

Re: document that read built-in can't return zero-length string in the middle of input

2024-01-13 Thread Martin D Kealey
Random irreversible behaviour change strikes again. This changed in Bash 4.3.0, and to make matters worse, shopt -s compat42 does not restore the previous behaviour. Up to Bash 4.2, read -N1 would indeed set the receiving variable to empty while returning a zero status, having read only one

Re: document that read built-in can't return zero-length string in the middle of input

2024-01-12 Thread Greg Wooledge
On Sat, Jan 13, 2024 at 02:06:08AM +0700, Robert Elz wrote: > Date:Fri, 12 Jan 2024 07:15:35 -0500 > From:Greg Wooledge > Message-ID: > > | This was one of the things I tested: > > Perhaps intended to, but didn't, or not in this example: > > | { read -N1; read

Re: document that read built-in can't return zero-length string in the middle of input

2024-01-12 Thread Lawrence Velázquez
On Fri, Jan 12, 2024, at 2:06 PM, Robert Elz wrote: > ps: the use of process substitution there is just silly, it would work > just as well, and be easier to understand if written: > > printf '\\\nabc' | { read -N1; read -r b c; }; declare -p REPLY b c Presumably Greg was just preventing

Re: document that read built-in can't return zero-length string in the middle of input

2024-01-12 Thread Robert Elz
Date:Fri, 12 Jan 2024 07:15:35 -0500 From:Greg Wooledge Message-ID: | This was one of the things I tested: Perhaps intended to, but didn't, or not in this example: | { read -N1; read -r b c; } < <(printf \\nabc); declare -p REPLY a b c Rewrite that, correctly

Re: document that read built-in can't return zero-length string in the middle of input

2024-01-12 Thread Greg Wooledge
On Fri, Jan 12, 2024 at 03:26:31PM +0700, Robert Elz wrote: > Date:Thu, 11 Jan 2024 20:02:04 -0500 > From:Greg Wooledge > Message-ID: > > | What actually counts is how many > | characters are *stored* in the variable, not how many characters are > | *read*

Re: document that read built-in can't return zero-length string in the middle of input

2024-01-12 Thread Robert Elz
Date:Thu, 11 Jan 2024 20:02:04 -0500 From:Greg Wooledge Message-ID: | What actually counts is how many | characters are *stored* in the variable, not how many characters are | *read* from the input. I suspect that is the root of the issue here, you're

Re: document that read built-in can't return zero-length string in the middle of input

2024-01-11 Thread Greg Wooledge
On Thu, Jan 11, 2024 at 08:02:04PM -0500, Greg Wooledge wrote: > And this for the help text: > > -N nchars return only after storing exactly NCHARS characters, unless >EOF is encountered or read times out, ignoring any NUL or >delimiter characters Actually,

Re: document that read built-in can't return zero-length string in the middle of input

2024-01-11 Thread Greg Wooledge
On Fri, Jan 12, 2024 at 01:29:19AM +0100, Ángel wrote: > One might say "reading exactly nchars characters into the name", I would still find that confusing. What actually counts is how many characters are *stored* in the variable, not how many characters are *read* from the input. > but > given

Re: document that read built-in can't return zero-length string in the middle of input

2024-01-11 Thread Ángel
On 2024-01-11 at 09:29 -0500, Chet Ramey wrote: > On 1/11/24 2:37 AM, ilya Basin wrote: > > 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

Re: document that read built-in can't return zero-length string in the middle of input

2024-01-11 Thread alex xmb sw ratchev
On Thu, Jan 11, 2024, 15:29 Chet Ramey wrote: > On 1/11/24 2:37 AM, ilya Basin wrote: > > 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

Re: document that read built-in can't return zero-length string in the middle of input

2024-01-11 Thread Greg Wooledge
On Thu, Jan 11, 2024 at 09:29:03AM -0500, Chet Ramey wrote: > The read builtin skips over NUL characters because you can't store them > as part of the value of a shell variable. That seems obvious. I would argue that it's not obvious at all when using -N. The help text for -N says "return only

Re: document that read built-in can't return zero-length string in the middle of input

2024-01-11 Thread Chet Ramey
On 1/11/24 2:37 AM, ilya Basin wrote: 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