Passing control back to the shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing control back to the shell script
# 1  
Old 06-04-2016
Passing control back to the shell script

Hi All,

I have a shell script(test_abc.sh) with the following shell commands, which are invoking the same shell script with different parameters.

test_abc.sh
Code:
. ./test.sh abc >> test.log
. ./test.sh xyz >> test.log
. ./test.sh pys >> test.log
. ./test.sh abc >> test.log
.
.

test.sh
Code:
if [ "$1" = "abc" ]; then
echo "found $1"
exit 0
else 
echo "not found $1"
exit 1

when i execute test_abc.sh .. i only get the following in the log

Code:
found abc

My motive is that all the shell commands in test_abc.sh are run and i get the status of each of them in the test.log. But it seems like 'exit 0' and 'exit 1' are not working in my favor and are logging me out. Request your expert help here.

Thanks in advance,
Dev
# 2  
Old 06-04-2016
Hi,

First hint:
Please close your if-construct with fi !

Code:
if expression
then
      then-commands...
else
      else-commands...
fi

maybe it works not as you suspect. But it works. The exit status is not printed, it is only set. You get your exit status with: $? And $? ist set new after every command. So if you want to get the exit status, you must read it directly after the command execution, or it is overwritten with the exit status of the next command.

Try this:


Code:
./test.sh abc >>test.log ; echo $? >>tst.log

# 3  
Old 06-04-2016
try executing your sub-scripts in debug mode to find how the flow is working.
bash -x ./test.sh abc

exit # could be working the way it is supposed to and its a wrong choice.. read man page for exit
You may want to try continue or return # commands.
# 4  
Old 06-04-2016
Quote:
...and are logging me out.
Ahh. The new answer shows what I've missed to read.

What's regarding the logout is the way you are calling your scripts:

Code:
. ./test.sh bla blub

calling a script with the dot-command(=".") is special. Dot means: don't create a new process. Run the Programm in the current process. And when you call the builtin exit in your script, your current shell is closed - as you requested by this command.

Simple solution: Don't use the dot command. Just call your script:

Code:
./test.sh bla blub

This User Gave Thanks to stomp For This Post:
# 5  
Old 06-29-2016
Thanks Stomp , that was helpful Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing error message back to script

I have one script that calls another script during execution. The other script does some processing, then either returns with exit 0 (if successful), or exits with error code numbers (if failed). However, in addition to the error code, I would like for that second script to be able to pass a... (4 Replies)
Discussion started by: AcerAspirant
4 Replies

2. Shell Programming and Scripting

Ampersand not giving back the control (Korn shell)

OS version : AIX 6.1 Shell : Korn When you 'postfix' a command with ampersand (&) , it is supposed to run in the background and give you back the control. I tested this with ping command (by default it pings every 1 second ) After I ran the below ping command with ampersand, I pressed... (3 Replies)
Discussion started by: polavan
3 Replies

3. Shell Programming and Scripting

Version Control Through the Shell Script

Version Control Through the Shell Script Hi Guys, Apologize for the big request, please take some time and read it completely... This is Very important for me, and ur help is Very much Appriciated. I want to maintain the Version control to all my scripts running in Production server, I am... (6 Replies)
Discussion started by: Anji
6 Replies

4. Shell Programming and Scripting

how to write shell script to take back up

Helo, I want to write shell script which takes back of all binaries (exe files). and when i uninstall the upgraded system which automatically restore the old binary which we have take as back up. can u tell me how to write such shell scripts. Regards, Amit (5 Replies)
Discussion started by: amitpansuria
5 Replies

5. Shell Programming and Scripting

Passing a variable from a child script back to the parent

Hi I have written a script using ftp to get files from one server and copy them to 2 dirrerent servers. I wish to call this script from a parent script that will check the number of files copied and run a check sum for each file. As the filenames for the files in the get portion of the script... (3 Replies)
Discussion started by: Andy82
3 Replies

6. Solaris

how to get back a SVM volume to solaris control

hi.., help me in this case... 1) now the disk is under disksuite, its have some mirrored volume. how can i get back this disk to OS control. 2) how can i know the a SVM volume avalable,used space. and the filesystem size on tht volume please help in this i am bigginer... (5 Replies)
Discussion started by: b.janardhanguru
5 Replies

7. Shell Programming and Scripting

How to Control Cronjobs using Shell Script??

Hi All, Now i am running the 3 oracle procedures one by one manually. Query: If 1st Procedure OUT_PUT is Success, then call 2nd Procedure. If 2nd Procedure OUT_PUT is Success, then call 3rd Procedure. If 1st Procedure is failed, then no need of calling the other ... (8 Replies)
Discussion started by: hanu_oracle
8 Replies

8. Shell Programming and Scripting

control over shell script

Hi.. I have a perl program that uses "system" to execute a shell script called startengine. The script "startengine" itself calls a lot of other smaller scripts to setup the engine etc. It finally has to execute ./engine which is another shell script which is long and takes a long time to... (3 Replies)
Discussion started by: JLJ
3 Replies

9. Shell Programming and Scripting

passing oracle parameters back to Shell

Hi All, Does anyone have any solutions for passing back multiple variables back to the SHELL from a call to an ORACLE procedure: eg #username='scott' #password='tiger' #database='orcl' username='ITGCD03D03' password='tC5epIew' database='ITGCD03D' sqlplus -s... (4 Replies)
Discussion started by: satnamx
4 Replies

10. Programming

Passing Parameters and getting values back from a c program to Shell script

I am having a shell script which has to be called from a C program. I have to pass two parameters to this script. HOw can I do that? eg: int main() { char st1; char str2; // call a shell script call_sh(str1,str2) where call_sh is the name of the shell script. then i need to get the return... (5 Replies)
Discussion started by: Rajeshsu
5 Replies
Login or Register to Ask a Question