tech-userlevel archive

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

Re: sh(1) read: add LINE_MAX safeguard and "-n" option



On Fri, Sep 27, 2024 at 06:52:31PM +0700, Robert Elz wrote:
>     Date:        Fri, 27 Sep 2024 12:25:49 +0200
>     From:        tlaronde%kergis.com@localhost
>     Message-ID:  <ZvaILZGn-fMR0kOI%kergis.com@localhost>
> 
> 
>   | I have an algebraic mind: I always think of rule. A line, sometime
>   | ago, was considered a sequence of bytes ending by the first appearance
>   | of '\n'. If a "line" is defined more generally as a sequence of bytes
>   | ending by the first appearance of whatever byte delimiter,
> 
> But it isn't - what a line is is defined, and it isn't that.
> The delimiter is just what terminates the read, just as the
> byte count given to -n does.  That might take a fractional line
> or many lines to achieve (given various combinations of -d and -n).
> 
>   | But could you state it clearly (not \`a la POSIX :-^)
>   | in the man page?
> 
> That would be my hope.   But writing English was never one of my
> better achievements, as some of these e-mails should reveal.

If I understand correctly your view, the explanation could be
something around this (I mean for the idea; for the way it is
expressed in some kind of english...):

"A line is always considered a sequence of bytes ended by the first
newline character. A continuation line is an escaped newline, when
escaped sequences are interpreted. The end of the stream terminates
forcibly the reading.

The backslash is the escaping character and escaped sequences
(including continuation lines) are interpreted unless the ``-r''
option is given.

By default, in this stream of lines, the primary splitting is done in
coïncidence with the not escaped newline, thus chopping lines.

The ``-d'' option allows to split the stream at another character than
the newline.

The ``-n'' option allows to define the maximum number of bytes of a
primary chunk, in case the delimiter is not encountered before.

The ``-N'' option allows to chop the stream disregarding any notion of
a delimiter, by chopping every n number of bytes.

The IFS allows a secondary splitting in fields of the chopped portion,
assignement of fields being done in order to the variables given as
arguments, exceeding fields being assigned to the last variable given."

-- 
        Thierry Laronde <tlaronde +AT+ kergis +dot+ com>
                     http://www.kergis.com/
                    http://kertex.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C


Home | Main Index | Thread Index | Old Index