mainThe GNU Bourne-Again SHell - Support: sr #110714, LINENO is inconsistent after...

 
 

sr #110714: LINENO is inconsistent after multiline piped commands

Submitter:  None
Submitted:  Tue 06 Sep 2022 08:25:17 PM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Done
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 28 Sep 2022 03:55:47 PM UTC, comment #2: 

Thanks for the report. This is the result of the () subshell being the non-terminal pipeline element, and not restoring enough saved state in that case.

Chet Ramey <chet>
Group administrator
Tue 06 Sep 2022 10:16:42 PM UTC, comment #1: 

(This issue was initially discussed on Stackoverflow: https://stackoverflow.com/q/73625481/318354 )

Arnauld VM <arnauldvm>
Tue 06 Sep 2022 08:25:17 PM UTC, original submission:  

Line numbers generated when executing the following script are unexpected:

"test.sh":

trap 'echo $LINENO' DEBUG

:
(:) |
# Add any number of lines here
:
:


This returns 3 - 6 - 5, while I expected to get 3 - 6 - 7.

The issue appears only when the pipe contains at least one sub-shell (created with parentheses) before the last command.

The last command may span any number of lines, they are not taken into account.

The following variations of the script behave as expected:

  • No sub-shell (3 - 4 - 6 - 7):



trap 'echo $LINENO' DEBUG

:
: |
# Add any number of lines here
:
:


  • last piped command stays on the same line (3 - 4 - 5):



trap 'echo $LINENO' DEBUG

:
(:) | :
:


  • sub-shell only on the last piped command (3 - 4 - 8):



trap 'echo $LINENO' DEBUG

:
: | (
:
)
:


I tested with several versions of bash. By bisecting I could find out the change of behavior appeared between 4.4.23 and 5.0.0:


$ docker run -it -v "$(pwd)/test.sh":/tmp/test.sh bash:4.4.23 bash /tmp/test.sh
3
6
7
$ docker run -it -v "$(pwd)/test.sh":/tmp/test.sh bash:5.0.0 bash /tmp/test.sh
3
6
5
+verbatim+

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  • -email is unavailable- added by arnauldvm (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-09-28 chet StatusNone Done

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code