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

 
 

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

Submitted by:  None
Submitted on:  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

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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: https://gitlab.com/gitlab-org/gitlab-ce/issues/41581

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

> : | eval "<script>"


see https://gitlab.com/gitlab-org/gitlab-runner/blob/master/shells/bash.go#L205

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'"
> TRAP
> $


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


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

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


Note: without the pipe, it is also working:

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

Anonymous

 

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

Attach Files:
   
   
Comment:
   

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)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    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.5