On 8/10/25 4:51 PM, Wiley Young wrote:
Hey,

What happens:
   When an alias definition includes line continuation, at the global scope
for each such line continuation the value of LINENO is off by one,
effectively incremented twice. Regular newlines in alias definitions do not
appear to cause any inaccuracies.

What I expected:
   For LINENO to be an accurate reflection of literal file lines as measured
by `wc -l`.

There is some variation out there. mksh is the only shell that behaves as
you want. Bash does as you observe. Every other shell I tested (dash, yash,
ksh93, NetBSD sh, FreeBSD sh) exits after the first test against
LINENO = 10 with LINENO set to 12, indicating that they increment LINENO
when encountering newlines in alias definitions. Everyone -- with mksh
again the outlier -- increments LINENO when encountering escaped newlines
in alias definitions.

I can see their point: the way alias expansion is defined, it's tokenized
exactly as if the alias value had appeared in the input. POSIX puts it this
way:

"the value of the alias shall be processed as if it had been read from the
input instead of the TOKEN, with token recognition (see 2.3 Token
Recognition) resuming at the start of the alias value."

With that definition, it's reasonable to ask why bash doesn't increment
LINENO when it encounters an unesacped newline in an alias expansion, like
it does when the newlines are escaped. This is, of course, the opposite of
your desired resolution.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to