bug-bash
[Top][All Lists]
Advanced

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

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


From: Brad Spencer
Subject: Simple exit trap doesn't run in newer versions of bash
Date: Fri, 25 Jan 2019 11:22:07 -0400
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0

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.

This last command _does_ produce "WORKS" on Ubuntu 12's bash 4.2.25(1)-release. But it does not work on the following versions:

5.0.0(1)-release
4.4.19(1)-release
4.4.12(1)-release
4.3.48(1)-release
4.2.46(2)-release

Substituting "mkdir" for "touch" gives similar results. Some commands exhibit this behaviour and some don't.

Is this a bug? If not, can someone explain why the last command behaves differently?

--
Brad Spencer



reply via email to

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