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.

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..."

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.

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

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.