[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bash-bug
Subject:    Re: Scripts passed into "-c" with an embedded newline won't execute trap if last command fails
From:       Chet Ramey <chet.ramey () case ! edu>
Date:       2016-04-22 19:50:57
Message-ID: 571A80A1.6010803 () case ! edu
[Download RAW message or body]

On 4/21/16 12:48 PM, Brian Vandenberg wrote:

> Description:
> 
> I ran into this issue while experimenting with gnu make and .ONESHELL. 
> I've boiled the issue down to the following simple example:
> 
> $ newline=$'\n'
> $ bash -e -c "trap 'echo handler' INT ERR;/bin/true; sleep 2;
> ${newline}/bin/false"
> 
> It will successfully trap if I do the following:
> 
> * hit ^C during the sleep
> * use "false" instead of "/bin/false" because that'll use a builtin
> * trap on EXIT instead
> * remove the newline
> * add another command after "/bin/false"
> * add another command before "/bin/false" without a newline after it
> 
> If I replace "/bin/false" with a sleep then hit ^C then the INT trap also
> won't execute.

Thanks for the report.  A variant of your suggestion will be in the next
release of bash.

(As an aside, many shells optimize the fork out to the extent they won't
execute the trap if you use sleep as the last command and send the shell
a SIGINT.)

Chet

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic