help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Bash Trap: How to Get Line Number of a Subprocess with N


From: Steve Amerige
Subject: Re: [Help-bash] Bash Trap: How to Get Line Number of a Subprocess with Non-Zero Status
Date: Mon, 2 Jan 2017 04:59:49 -0500
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

   On 12/30/2016 12:50 PM, Chet Ramey wrote:

It's the difference between a simple command, which has a line number, and
a subshell command, which does not.  The subshell command's line number is
derived from the execution context, which is relative to the start of the
function.  The OP wants the subshell's line number to be absolute, like the
simple command's, and not relative to the start of the function, as it is
now.

   From an end-user's perspective, it is unexpected that the LINENO has
   the value of the
   beginning of the function instead of the line at which the ERR was
   caught by trap.
   While the "inside" of the subshell might have it's own characteristics,
   the inside must
   eventually meet the "outside" of the subshell... at which point, an end
   user can reasonably
   expect that an error is reported in a common-sense way with the line
   number that is
   seen in the script file itself. While the current behavior can be
   explained, that doesn't
   mean it is expected by end users or makes sense.
   Using any other line number for LINENO also makes it harder to debug
   scripts, of course,
   since the line number being reported isn't as helpful.
   Is there any way this can be fixed... or introduced as a feature (e.g.,
   with some
   set -o or shopt flag)?  A fix would help out a significant number of
   people. As it is, a
   workaround now is to use:
       $(...)
   instead of:
       (...)
   to get the expected behavior. But, this can mean some significant
   re-writing of code.
   Enjoy,
   Steve Amerige
   Server Science Incorporated
   [1]Eggsh: A Powerful and Reusable Bash Scripting Platform, an
   Open-Source Project

References

   1. https://eggsh.com/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]