[Toybox] Would someone please explain what bash is doing here?

Chet Ramey chet.ramey at case.edu
Sun May 24 14:32:57 PDT 2020


On 5/24/20 5:05 PM, Rob Landley wrote:
> On 5/24/20 3:46 PM, Chet Ramey wrote:
>>> No, I meant the LINENO on the second line isn't noticing it's on a later line,
>>> it's now reporting the first line for both LINENOs, and I thought my initial
>>> confusion was about it NOT doing that?
>>
>> I'm not sure myself.
>>
>> The backslash-newline gets removed, so the command is a single logical
>> line, which, since the lexer was on line 1 when the parser figured out it
>> was parsing a simple command, is all on line 1. The simple command gets
>> the line number where the lexer is when the parser reduces to a simple
>> command. That's definitely a yacc/bison artifact.
> 
> In new tab:
>   $ echo $LINENO \
>   > $LINENO
>   1 1
>   $ echo $LINENO
>   3
> 

Yep. You read $LINENO, hit the space that terminates the token, return
WORD, the parser figures out it's parsing a simple command, and sets
the command's line number to the current line number: 1.

> In new tab:
>   $ echo $LINENO\
>   > $LINENO
>   22
>   $ echo $LINENO
>   3
> 
> It cares about the space.

Of course it does! The space terminates the token! You can't return the
first $LINENO until you process the backslash-newline and find a
metacharacter that ends the word, which is the newline after the second
$LINENO.

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



More information about the Toybox mailing list