0

I have this in a bash script:

(
  set -o pipefail
  echo "foobar" | bash
  set +o pipefail
)

do I need to reset pipefail setting, or can I just omit that line? In other words, does the pipefail setting in the subshell affect the parent?

So that means I assume that this:

(
  set -o pipefail
  echo "foobar" | bash
)

is really no different than the above?

  • they probably aren't called bash flags / settings...if you can correct me on the terminology that would be good – Alexander Mills May 7 '18 at 21:52
2

To quote the man page:

Changes made to the subshell environment cannot affect the shell's execution environment.

You can test your case easily:

$ set +o pipefail
$ (set -o pipefail)
$ shopt -o | grep pipefail
pipefail        off
  • Yeah that's what I though, so no need to unset things at the end of the subshell I guess – Alexander Mills May 7 '18 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.