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: Chet Ramey
Subject: Re: [Help-bash] Bash Trap: How to Get Line Number of a Subprocess with Non-Zero Status
Date: Fri, 30 Dec 2016 12:50:41 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.6.0

On 12/29/16 10:39 PM, Eduardo Bustamante wrote:

> I'm adding the bug-bash list, since I think this is actually a bug in
> the parse_comsub function, or maybe in execute_command_internal. I
> haven't been able to figure it out yet. What I do know is that these
> two should behave the same:
> 
>     address@hidden:~$ cat -n h
>          1  #!/bin/bash
>          2  shopt -s extdebug
>          3  main() {
>          4  trap 'echo $LINENO' ERR
>          5  (exit 17)
>          6  }
>          7  main
>     address@hidden:~$ ./h
>     3
> 
> --- vs ---
> 
>     address@hidden:~$ cat -n i
>          1  #!/bin/bash
>          2  shopt -s extdebug
>          3  main() {
>          4  trap 'echo $LINENO' ERR
>          5  `exit 17`
>          6  }
>          7  main
>     address@hidden:~$ ./i
>     5
> 
> There's no actual reason for these two to be different, 

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.

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



reply via email to

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