LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-05-2010, 12:33 AM   #1
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
export a variable


Hi all..

I have following script.
Code:
#!/bin/bash
export VAR="shell"
echo " $VAR in parent "
bash
echo "shell in child "
If i execute this script, the output is just

Code:
shell in parent
Why can't I see the output shell in child ?

Can any one clear this doubt..
 
Old 02-05-2010, 12:45 AM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
The reason is because you have that `bash` executable line in there, second from last line.
Because of that, the first half of the code gets executed in one shell instance (parent), and then `bash` is invoked (child), spawning a new shell which has no idea about what was going on in the first shell which called it.

If you put a "&" sign after the word "bash" then you will be able to see the line you are looking for; however, it will be coming from the same shell that printed the first line, rather than from the child shell.

If you tell us what precisely is the goal of this exercise, maybe someone can help you get the desired results?

Sasha
 
Old 02-05-2010, 12:45 AM   #3
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Rep: Reputation: 32
Quote:
Originally Posted by vinaytp View Post
Hi all..

I have following script.
Code:
#!/bin/bash
export VAR="shell"
echo " $VAR in parent "
bash
echo "shell in child "
If i execute this script, the output is just

Code:
shell in parent
Why can't I see the output shell in child ?

Can any one clear this doubt..
bash. Here you are calling the bash command means that you are calling another bash shell.
To be more understandable you are calling a BASH inside a BASH.
enter exit to come out of that BASH environment to your previous BASH environment as fallows:
Code:
[Ashok@station130 ~]$ sh temp.sh
 shell in parent
[Ashok@station130 ~]$ exit
exit
shell in child
Now you are able to see the output shell in child
 
  


Reply


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
unset export variable mira.mikes Linux - Desktop 4 03-17-2009 03:31 AM
variable export in shell MarioT Programming 3 05-17-2006 12:52 AM
export cd variable? rjwhite Linux - Games 1 12-17-2005 06:47 PM
Export variable loopoo Linux - Newbie 4 08-08-2005 05:08 AM
BASH variable export Barbarian Programming 2 11-27-2001 09:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:20 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration