The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 06:09 AM
Invoking shell script from html/jsp page bubeshj Shell Programming and Scripting 2 06-28-2006 01:53 PM
invoking one shell script from other ajay xavier Shell Programming and Scripting 3 05-24-2006 03:39 AM
Returning values from child to parent shell acheepi Shell Programming and Scripting 4 07-15-2005 03:25 PM
Wrong Shell Invoking My Script On Linux kowrip Shell Programming and Scripting 3 09-10-2003 10:18 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-25-2006
gurukottur gurukottur is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 40
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.
  #2 (permalink)  
Old 09-25-2006
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
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..."
  #3 (permalink)  
Old 09-25-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
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.
  #4 (permalink)  
Old 09-26-2006
Dhruva's Avatar
Dhruva Dhruva is offline
Registered User
  
 

Join Date: Mar 2006
Location: India
Posts: 255
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
  #5 (permalink)  
Old 09-26-2006
gurukottur gurukottur is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 40
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.
  #6 (permalink)  
Old 09-26-2006
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
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.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:17 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0