Setting bash flags in subshells - does it affect parent shell?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












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?







share|improve this question



















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














up vote
0
down vote

favorite












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?







share|improve this question



















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












up vote
0
down vote

favorite









up vote
0
down vote

favorite











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?







share|improve this question











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?









share|improve this question










share|improve this question




share|improve this question









asked May 7 at 21:51









Alexander Mills

1,885929




1,885929











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
















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















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




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










1 Answer
1






active

oldest

votes

















up vote
2
down vote













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





share|improve this answer





















  • Yeah that's what I though, so no need to unset things at the end of the subshell I guess
    – Alexander Mills
    May 7 at 23:00










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442414%2fsetting-bash-flags-in-subshells-does-it-affect-parent-shell%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote













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





share|improve this answer





















  • Yeah that's what I though, so no need to unset things at the end of the subshell I guess
    – Alexander Mills
    May 7 at 23:00














up vote
2
down vote













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





share|improve this answer





















  • Yeah that's what I though, so no need to unset things at the end of the subshell I guess
    – Alexander Mills
    May 7 at 23:00












up vote
2
down vote










up vote
2
down vote









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





share|improve this answer













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






share|improve this answer













share|improve this answer



share|improve this answer











answered May 7 at 22:51









Grisha Levit

20116




20116











  • Yeah that's what I though, so no need to unset things at the end of the subshell I guess
    – Alexander Mills
    May 7 at 23:00
















  • Yeah that's what I though, so no need to unset things at the end of the subshell I guess
    – Alexander Mills
    May 7 at 23:00















Yeah that's what I though, so no need to unset things at the end of the subshell I guess
– Alexander Mills
May 7 at 23:00




Yeah that's what I though, so no need to unset things at the end of the subshell I guess
– Alexander Mills
May 7 at 23:00












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442414%2fsetting-bash-flags-in-subshells-does-it-affect-parent-shell%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Christian Cage

How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?