Line numbers generated when executing the following script with bash (5.1.0) are unexpected:
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 ( )) 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 : : | ( : ) :