Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
1  
See bugs.debian.org/cgi-bin/bugreport.cgi?bug=698411 It's been fixed since. –  Stéphane Chazelas Jun 27 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 at 13:10
    
If you or anyone else want to do, please feel free. See the bash Changelog for details. –  Stéphane Chazelas Jun 27 at 14:50
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.