returning to the parent shell after invoking a script within a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting returning to the parent shell after invoking a script within a script
# 1  
Old 09-25-2006
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  
Old 09-25-2006
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  
Old 09-25-2006
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  
Old 09-26-2006
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  
Old 09-26-2006
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  
Old 09-26-2006
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Control from UNIX script is not returning to the Parent program

Hi All, My program flow is as below Windows batch -- > Cygwin batch --> zsh script There are multiple Cygwin batch scripts that are called from Windows batch file . But when i am executing the first cygwin batch script the control goes to the zsh file and executes and stoping from... (1 Reply)
Discussion started by: Hypesslearner
1 Replies

2. Shell Programming and Scripting

Invoking Application in Shell Script

Hi All, I have a scenario : 1. A list of servers naming server21, server 22, server 23 etc. This list of servers is separate for my environments. Env1 has 3 server Env2 has 5 serves Env3 has 10 servers 2. Each server accesses application through which I want to invoke some method. So... (7 Replies)
Discussion started by: ankur328
7 Replies

3. Shell Programming and Scripting

Child exiting and not returning to parent script

I am having a parent scripts which reads a file with child scripts name. I need to read one by one child script , execute it and 1. If child script fails send mail to the team with the log file 2. If the child script executes fine then proceed with the next child script execution. #!... (3 Replies)
Discussion started by: nw2unx123
3 Replies

4. Shell Programming and Scripting

Problem invoking shell script

whats wrong here?! ________________ #!/bin/sh # FILE: clean_dirs # GOAL : To clean up directories used in Oracle processing # LANGUAGE : shell script (sh) # PARAMETERS : Input_File # 11/07/02 acri - modified to cd into the directory so it will... (7 Replies)
Discussion started by: gillraj
7 Replies

5. Shell Programming and Scripting

Invoking one shell script from another unix box

Hello All, I have a shell script A which is in one unix box. Also i have a script B in another unix box. Now i'm struggling to find a way to invoke A shell script from B shell script. Is it possible to do this in any way..Request you anybody please help me in this point. Thanks in advance. (6 Replies)
Discussion started by: RSC1985
6 Replies

6. UNIX for Advanced & Expert Users

Invoking shell script with perl command.

Hi All, I am using the following command to invoke the shell script from a perl command. perl -i.bak -pe'BEGIN { $cmd = "/opt/coreservices/tomcat-5.5.9/bin/digest.sh -a sha"; } s/(password=")(*)/ $1.`$cmd $2|cut -d: -f2|tr -d "\n"` /e ' $CATALINA_HOME/conf/tomcat-users.xml I need... (1 Reply)
Discussion started by: nua7
1 Replies

7. Shell Programming and Scripting

invoking a shell script inside cgi shell script

Hi, I have an HTML form through which I get some text as input. i need to run a shell script say script.sh inside a perl-cgi script named main_cgi.sh on the form input. I want to write the contents of the form in a file and then perform some command line operations like grep, cat on the text... (2 Replies)
Discussion started by: smriti_shridhar
2 Replies

8. Shell Programming and Scripting

Invoking Shell Script via php

list me commands to invoke a shell script from php once the submit button is clicked in the php page. Requirement is Once a submit button is clicked it should run a script that displays the outcome of the script in a html/php. Please help. Thanks in Advance, BubeshJ (2 Replies)
Discussion started by: bubeshj
2 Replies

9. Shell Programming and Scripting

invoking one shell script from other

hi, i am one day old in shell scritpting. how to invoke one shell script from the other? For eg.i have two shell scripts A.sh and B.sh. Inside A.sh i need to invoke B.sh and the return code of A.sh should be the value returned by B.sh. it would be better if you provide any sample shell... (3 Replies)
Discussion started by: ajay xavier
3 Replies

10. Shell Programming and Scripting

Returning values from child to parent shell

I need to send the status from child shell failure to parent shell. I would like to know how could we accomplish this. My parent.sh is as below: #!/bin/ksh set -x echo "I am in parent shell now..." child.sh ret_stat=$? echo "rest_stat=$ret_stat" echo "I am below parent shell end..." ... (4 Replies)
Discussion started by: acheepi
4 Replies
Login or Register to Ask a Question