LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   bash: set <option> and sub-shells (http://www.linuxquestions.org/questions/programming-9/bash-set-option-and-sub-shells-4175424980/)

druuna 08-31-2012 10:56 AM

bash: set <option> and sub-shells
 
With the following in mind:
Code:

#!/bin/bash

set +h

./script1.sh

Is set +h also set in script1.sh (and its sub-shells)?

Variables need to be explicitly exported to be recognized in a sub-shell, which makes me wonder if set -/+ X needs to be set in every sub-shell.

Haven't been able to find this info in the bash man page.

Thanks in advance!

ukiuki 08-31-2012 11:04 AM

I did found this, hope this helps: http://www.gnu.org/software/bash/man...he-Set-Builtin

Regards

druuna 08-31-2012 11:15 AM

Quote:

Originally Posted by ukiuki (Post 4769247)

That info is also in the man page, but it does not answer my question.

colucix 08-31-2012 11:19 AM

I'm sure you already did a couple of tests and they revealed that shell options are not inherited from the parent shell. Indeed, this is not clearly mentioned anywhere. Maybe an explanation close to what really happens is given here: http://www.gnu.org/software/bash/man...on-Environment.

Shell options are cited in the list of the execution environment items, but not in the list of items inherited by a subshell. Maybe an indirect and somewhat obscure way to assert the evidence of the facts! :jawa:

druuna 08-31-2012 11:36 AM

Quote:

Originally Posted by colucix (Post 4769255)
I'm sure you already did a couple of tests and they revealed that shell options are not inherited from the parent shell.

Yep, I did and I got confused by the results (which is explained by your link). My assumption was that some are and some are not inherited depending on other factors (from the link: set -e is exported when not in POSIX mode).

Assuming that none are inherited is probably the smart thing to do. Better safe then sorry.......

Quote:

Originally Posted by colucix (Post 4769255)
Indeed, this is not clearly mentioned anywhere. Maybe an explanation close to what really happens is given here: http://www.gnu.org/software/bash/man...on-Environment.

Shell options are cited in the list of the execution environment items, but not in the list of items inherited by a subshell. Maybe an indirect and somewhat obscure way to assert the evidence of the facts! :jawa:

Thank you!

NevemTeve 08-31-2012 12:03 PM

untested#1:

Code:

#!/bin/bash

bash +h ./script1.sh

untested#2:

Code:

#!/bin/bash

set +h

source ./script1.sh



All times are GMT -5. The time now is 03:33 AM.