Operating System - Linux
1753798 Members
8029 Online
108805 Solutions
New Discussion юеВ

Exiting a script within a script

 
SOLVED
Go to solution
TheJuiceman
Super Advisor

Exiting a script within a script

Hey gang,

I am wanting to execute a 'su - user -c "scriptA"' inside a script (say scriptB). However, scriptA requires an interrupt (like a return) to exit. Is there a way to pass variables to scriptA through scriptB while still switching users? Thanks for the help.
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor
Solution

Re: Exiting a script within a script

Hi:

See if this helps:

# cat /tmp/scriptA
#!/usr/bin/sh
echo "...in A..."
su juiceman -c "/tmp/scriptB $@ < /dev/null"
echo "...in A..."
exit 0

# cat /tmp/scriptB
#!/usr/bin/sh
echo "B sees $@"
echo "reading input"
read
echo "exiting B..."
exit 0

...Run as:

# /tmp/scriptA hello!
...in A...
B sees hello!
reading input
exiting B...
...in A...

Regards!

...JRF...
Victor Fridyev
Honored Contributor

Re: Exiting a script within a script

Hi,

If you don't want to press enter by yoursef,
you can use the following:

SCRIPT_WHICH_NEEDS_ENTER <<$LABEL

$LABEL

or

echo "\n"| SCRIPT_WHICH_NEEDS_ENTER

HTH
Entities are not to be multiplied beyond necessity - RTFM
TheJuiceman
Super Advisor

Re: Exiting a script within a script

thanks