[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, 25 Jan 2019 14:15:08 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 |
On 1/25/19 10:22 AM, Brad Spencer wrote:
> Consider the following commands:
>
> bash -c 'trap "echo WORKS" EXIT; touch x'
> (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.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
disable-optimize-fork.patch
Description: Text document