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