LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 08-31-2012, 10:56 AM   #1
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
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!
 
Old 08-31-2012, 11:04 AM   #2
ukiuki
Senior Member
 
Registered: May 2010
Location: Planet Earth
Distribution: Debian
Posts: 1,030

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

Regards
 
Old 08-31-2012, 11:15 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Original Poster
Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Quote:
Originally Posted by ukiuki View Post
That info is also in the man page, but it does not answer my question.
 
Old 08-31-2012, 11:19 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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!

Last edited by colucix; 08-31-2012 at 11:21 AM.
 
1 members found this post helpful.
Old 08-31-2012, 11:36 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Original Poster
Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Quote:
Originally Posted by colucix View Post
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 View Post
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!
Thank you!
 
Old 08-31-2012, 12:03 PM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,946

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
untested#1:

Code:
#!/bin/bash

bash +h ./script1.sh
untested#2:

Code:
#!/bin/bash

set +h

source ./script1.sh
 
  


Reply

Tags
bash, set, subshell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Can all shells read all environmental variables set by other shells? carlodelmundo Linux - Newbie 2 07-23-2010 03:03 PM
How are variables set for interactive shells? Josh000 Slackware 22 05-07-2010 01:19 AM
should you know other shells then bash? WOP1337 Linux - General 8 05-06-2007 09:30 PM
Bash and login shells Adrohak Linux - Software 3 11-18-2004 11:21 AM
wait in bash shells raypen Linux - Software 1 04-18-2003 03:19 PM


All times are GMT -5. The time now is 06:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration