mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.1k stars 336 forks source link

interp: different behavior of `pipefail` for multiline scripts #870

Closed Hades32 closed 1 year ago

Hades32 commented 2 years ago

I'm using Task and hit this issue and was directed here: https://github.com/go-task/task/issues/392#issuecomment-1141300882

I want my script to fail on pipe errors. cmd1 works/fails as expected, but cmd2 never fails:

  cmd1:
    cmds: 
    - set -o pipefail ; aws something | jq .someField
    - echo success # this never happens if aws fails

  cmd2:
    cmds: 
    - |
      set -e
      set -o pipefail
      aws something | jq .someField
      echo success # happens despite error in the aws command

Why does pipefail not work in the second case?