[Top][All Lists]

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

Re: Simple exit trap doesn't run in newer versions of bash

From: Chet Ramey
Subject: Re: Simple exit trap doesn't run in newer versions of bash
Date: Fri, 1 Mar 2019 16:01:33 -0500

> > (trap "echo WORKS" EXIT; touch x)
> > (trap "echo WORKS" EXIT && touch x)
> > bash -c 'trap "echo WORKS" EXIT; true'
> > bash -c 'trap "echo WORKS" EXIT; false'
> > bash -c 'trap "echo WORKS" EXIT; touch x && a'
> > bash -c 'trap "echo WORKS" EXIT; touch x; a'
> > 
> > They all produce the output "WORKS" as the trap runs on exit.  (Where "a"
> > is not a command or in the path and produces an error.)
> > 
> > Now consider this command:
> > 
> > bash -c 'trap "echo WORKS" EXIT && touch x'
> > 
> > On newer versions of bash, it produces no output.  Substituting different
> > commands in the trap or tracing it seems to indicate that the trap never 
> > runs.
> It's a case of bash being too aggressive optimizing the last command in
> the AND_OR list. Here's a patch that disables that optimization attempt
> while I look at alternatives.

Here's a better patch that doesn't just disable the fork optimization. Please
let me know how it works in your testing.


Attachment: optimize-connection-fork.patch
Description: Optimize AND_AND and OR_OR lists

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

reply via email to

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