1

I recently ran into a strange behavior. Trap doesn't get executed if inside grouping command:

$ cat ./1.sh
#!/usr/bin/env bash
set -eu
trap 'echo exit' EXIT
$ ./1.sh
exit
$ cat ./2.sh
#!/usr/bin/env bash
set -eu
echo test | { trap 'echo exit' EXIT; }
$ ./2.sh

Is it as it's supposed to be?

3
  • 1
    See bugs.debian.org/cgi-bin/bugreport.cgi?bug=698411 It's been fixed since. Jun 27, 2014 at 12:44
  • 1
    Indeed, I can confirm it works in bash-4.3.8, and doesn't work in bash-4.2.37. If you answer my question, I'll accept it. Also, it'd interesting to know in which version/commit it was fixed. The bug report you mentioned doesn't tells anything about it.
    – x-yuri
    Jun 27, 2014 at 13:10
  • If you or anyone else want to do, please feel free. See the bash Changelog for details. Jun 27, 2014 at 14:50

1 Answer 1

0

This is a bug that has been fixed somewhere between versions >4.2.37 and <=4.3.8. Here is supposedly relevant information from the changelog:

This document details the changes between this version, bash-4.3-alpha, and the previous version, bash-4.2-release.

...

sss. Fixed a bug that caused asynchronous group commands to not run any EXIT trap defined in the body of the command.

...

tttt. Fixed a problem that caused subshells to not run an EXIT trap they set.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .