Skip to content

Commit

Permalink
interp: support combining pipefail and errexit
Browse files Browse the repository at this point in the history
We supported both options separately,
but when used together, a command like

    false | true

would fail to exit the shell properly.

Add tests and fix the bug.

Fixes #870.
  • Loading branch information
mvdan committed Apr 16, 2023
1 parent ca2088c commit 818a409
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions interp/interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,14 @@ var runTests = []runTest{
"set -o pipefail; set -M 2>/dev/null | false",
"exit status 1",
},
{
"set -o pipefail; false | :; echo next",
"next\n",
},
{
"set -e -o pipefail; false | :; echo next",
"exit status 1",
},
{
"set -f; >a.x; echo *.x;",
"*.x\n",
Expand Down
1 change: 1 addition & 0 deletions interp/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ func (r *Runner) cmd(ctx context.Context, cm syntax.Command) {
wg.Wait()
if r.opts[optPipeFail] && r2.exit != 0 && r.exit == 0 {
r.exit = r2.exit
r.shellExited = r2.shellExited
}
r.setErr(r2.err)
}
Expand Down

0 comments on commit 818a409

Please sign in to comment.