sh icon indicating copy to clipboard operation
sh copied to clipboard

Different behavior of `pipefail` for multiline scripts

Open Hades32 opened this issue 2 years ago • 0 comments

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?

Hades32 avatar May 31 '22 13:05 Hades32