helpThe GNU Bourne-Again SHell - Support: sr #109840, bash does not execute traps...


sr #109840: bash does not execute traps defined in eval

Submitter:  None
Submitted:  Thu 11 Jul 2019 09:00:30 AM UTC
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Done
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment (Rich Markup)

Comment Type & Canned Response:


Tue 13 Aug 2019 02:11:28 PM UTC, comment #2: 

I got it. It will be fixed in the next devel branch push.

Chet Ramey <chet>
Project Administrator
Wed 17 Jul 2019 03:29:09 PM UTC, comment #1: 

So when is the trap supposed to execute? When the subshell that runs the right side of the pipe exits?

Chet Ramey <chet>
Project Administrator
Thu 11 Jul 2019 09:00:30 AM UTC, original submission:  

This was discovered while building a CI script with gitlab, see related issue:

Gitlab executes the a script with an available shell in the following way:

> : | eval "<script>"


I don't know why they use this pipe here, but when a trap is defined inside an eval does not fire the trap when the shell exits:

> $ bash -c ": | eval 'trap \"echo TRAP\" EXIT'"
> $

While it works fine in dash and zsh:

> $ dash -c ": | eval 'trap \"echo TRAP\" EXIT'"
> $

> $ zsh -c ": | eval 'trap \"echo TRAP\" EXIT'"
> $

And it works also in bash, when i run the eval in a subshell:

> $ bash -c ": | (eval 'trap \"echo TRAP\" EXIT')"
> $

Note: without the pipe, it is also working:

> $ bash -c "eval 'trap \"echo TRAP\" EXIT'"
> $



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.





    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-08-13 chet StatusNeed Info Done
    2019-08-13 chet StatusNone Need Info

    Back to the top

    Powered by Savane 3.10