[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Scripts passed into "-c" with an embedded newline won't execute trap
Re: Scripts passed into "-c" with an embedded newline won't execute trap if last command fails
Fri, 22 Apr 2016 15:50:57 -0400
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.7.2
On 4/21/16 12:48 PM, Brian Vandenberg wrote:
> 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;
> 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
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU address@hidden http://cnswww.cns.cwru.edu/~chet/