Fixing trap handling in bash