bug-bash
[Top][All Lists]
Advanced

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

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


From: Greg Wooledge
Subject: Re: document that read built-in can't return zero-length string in the middle of input
Date: Thu, 11 Jan 2024 20:02:04 -0500

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 that there's no mention that the NULs are never stored in
> variables, I would tend to add a line below saying e.g. "NUL characters
> cannot be stored in bash variables and are always ignored by read".

I would be as explicit as possible.  Don't require the reader to put
any pieces together themselves.

How about this for the man page:

    -N nchars
        read returns after storing exactly nchars characters in the
        first named variable (or REPLY if no variable is named), unless
        EOF is encountered or read times out.  read does not wait for
        a complete line of input; any delimiter characters encountered
        in the input are not treated specially, and do not cause read to
        return before storing nchars characters.  NUL characters are
        ignored, as they cannot be stored in variables.  The result is
        not split on the characters in IFS; the intent is that the
        variable is assigned exactly the characters read (with the
        exceptions of NUL and backslash; see the -r option below).  If
        multiple variable names are given, input is only stored in the
        first; all other variables will be empty.

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



reply via email to

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