The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Invoking Shell Script via php bubeshj Shell Programming and Scripting 2 06-30-2006 03:09 AM
Invoking shell script from html/jsp page bubeshj Shell Programming and Scripting 2 06-28-2006 10:53 AM
invoking one shell script from other ajay xavier Shell Programming and Scripting 3 05-24-2006 12:39 AM
Returning values from child to parent shell acheepi Shell Programming and Scripting 4 07-15-2005 12:25 PM
Wrong Shell Invoking My Script On Linux kowrip Shell Programming and Scripting 3 09-10-2003 07:18 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-25-2006
Registered User
 

Join Date: Apr 2006
Posts: 37
returning to the parent shell after invoking a script within a script

Hi everybody,

I have a script in which I'm invoking another script which runs in a subshell.

after the script is executed I want to return to the parent shell as some variables are set. However i'm unable to return to my original shell as the script which i'm calling inside is invoked in subshell and as a reason I'm running it in background.

(My script is as follows:

#!/bin/bash

do something

sh invoke_another_script.sh

do rest.)

Please help me with this.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-25-2006
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 758
Try this, maybe you will understand about the problem. Write these two scripts and then execute outer_script.sh

#!/bin/sh
# outer_script.sh
echo "This is the outer script"
sleep 2
echo "now going to execute inner script... "
sh inner_script.sh

echo "... back in outer script"
sleep 2
echo "and going to exit the outer script now"



#!/bin/sh
# inner_script.sh
echo "this is the inner script"
sleep 5
echo "going to exit the inner script..."
Reply With Quote
  #3 (permalink)  
Old 09-25-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,198
The subshell executes itself in its own environment inherited from the parent process.
The creations or modifications of variables in the subshell are lost when returning back to the parent.


Jean-Pierre.
Reply With Quote
  #4 (permalink)  
Old 09-26-2006
Dhruva's Avatar
Registered User
 

Join Date: Mar 2006
Location: India
Posts: 241
if you want to use those variables in calling script then run the inner script with .(dot) operator.

outer_script::
echo " i am in outer"
x=8
echo "value of x is $x"
. inner.sh
echo "value of x is $x"

inner_script::
x=6
Reply With Quote
  #5 (permalink)  
Old 09-26-2006
Registered User
 

Join Date: Apr 2006
Posts: 37
thanks for the replies,

I want to exit the shell which my inner script is invoking and return to the shell of the calling script.
Reply With Quote
  #6 (permalink)  
Old 09-26-2006
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 758
Quote:
Originally Posted by gurukottur
thanks for the replies,

I want to exit the shell which my inner script is invoking and return to the shell of the calling script.
Under normal circumstances, you don't have to do anything special to achieve that.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0