How to return programming to calling shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to return programming to calling shell script?
# 1  
Old 04-05-2013
How to return programming to calling shell script?

Hi,
I need to edit a shell script which is calling another shell script. At the moment the program returns to the command prompt after executing each called script. I need to change it to make it return to the calling script so that the user is able to make another choice to execute the next option without coming out of the program and going back in each time.

For example the calling shell script LoadMarkID.sh is something like:

HTML Code:
echo "Enter  L(Load id)   M(Mark id) :\c"
 read answer
 case $answer in
                       L) exec load_id.sh ;;
                       M) exec mark_id.sh ;;
                        *) invalid
esac
done
while called script load_id.sh is something like:

HTML Code:
sqlplus -s userid/pswd  @load_id.sql
 
echo "Press Return to exit \c"
read answer
trap  1 2 3
exit 0
At this point, I would like the program to return to LoadMarkID.sh so that the user has a choice of selecting the next option without first exiting the program and then coming back in.

I would appreciate some help in achieving this please.

thank you.
PTL
# 2  
Old 04-05-2013
remove the exit 0 line in the called script and wrap LoadMarkID.sh as follows
Code:
while 1 ; do
  clear
  echo "Enter  L(Load id)   M(Mark id) :\c"
   read answer
   case $answer in
                       L) exec load_id.sh ;;
                       M) exec mark_id.sh ;;
                        *) invalid
  esac
done

This User Gave Thanks to Skrynesaver For This Post:
# 3  
Old 04-05-2013
Because you are using 'exec', your original program ceases to exist and is replaced by this new one whenever you do so. It cannot return because there's nothing to return to.

If you don't want it to do that, remove the 'exec' keyword and it will run it externally and wait for it to quit.
This User Gave Thanks to Corona688 For This Post:
# 4  
Old 04-05-2013
wow!! You guys are great! thank you for both suggestions, I will try both and let you know how it goes.

thanks again.
PTL
# 5  
Old 04-08-2013
hi,
Are there any more suggestions to the problem I logged please? I have tried both the suggestions above but neither was successful. The programming still does not return to the calling script.

thank you
PTL
# 6  
Old 04-08-2013
Show your entire program, please, as well as the modifications you tried.
This User Gave Thanks to Corona688 For This Post:
# 7  
Old 04-08-2013
Does your calling script do anything after the script call?

What happens (as far as we can tell) is:
Main script calls script 2
Script 2
preforms action
exit 0 (success)
Main script can get return status (exit 0) of the called script
Main script either performs other tasks below your task selection code (if there are any) or exits.

You can use the exit status of the called script to take additional actions in the calling script.

Shell scripting tends to be pretty linear in that when one command completes, the next will start. Running another script, from the perspective of your main script is just like any other command.
The task selection code you provided only allows for one task selection, then it is done.

If your intention is to remain in the main script's task selection code, then you need to write a loop around the task selection code and add an exit item to your task selection code.

As stated by Corona688, removing the exec leaves your main script running, and the command to run a second script returns as expected. What happens then is up to the code in the main script.
This User Gave Thanks to [MA]Flying_Meat For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

calling pl/sql procedure from shell and return values

How could I call an Oracle PL/SQL procedure from any shell (bash) and catch returning value from that procedure (out param) or get a returning value if it's a function. also, I got into trouble when I tried to send a number as a param #!/bin/bash -e username=$1 pwd=$2 baza=$3... (0 Replies)
Discussion started by: bongo
0 Replies

2. Shell Programming and Scripting

calling 'n' number of shell scripts based on dependency in one shell script.

Hello gurus, I have three korn shell script 3.1, 3.2, 3.3. I would like to call three shell script in one shell script. i m looking for something like this call 3.1; If 3.1 = "complete" then call 3.2; if 3.2 = ''COMPlete" then call 3.3; else exit The... (1 Reply)
Discussion started by: shashi369
1 Replies

3. Shell Programming and Scripting

How to return the value from the called shell script to the calling sh script

Hi all, I have two ksh scripts #sample1.sh #!/bin/ksh . ./sample2.sh echo $fileExist #sample2.sh #!/bin/ksh func() { i=1 return $a } func echo $? Here how should I return the value of sample2.sh back to sample1.sh? Thanks in advance. (2 Replies)
Discussion started by: gp_singh
2 Replies

4. Shell Programming and Scripting

Calling another shell script

Hi there, I have an script reading content of a file and runs whatever command is specified there, as follows #!/bin/bash # Supposed to read from a file that commands are listed to be run # when the server starts for initialization CMD_FILE=/myScripts/startup/task2do.txt if ; then ... (2 Replies)
Discussion started by: james gordon
2 Replies

5. Shell Programming and Scripting

Get return value from PERL script calling from KSH

All: I am calling a PERL script from KSH. I need specific codes to be returned by the PERL Script. For ex: Ksh ----- result=`test.pl $FILE` My idea is to get the value of result from the test.pl, by specifically making the test.pl to print the return code. Since I had some other print... (1 Reply)
Discussion started by: ucbus
1 Replies

6. Shell Programming and Scripting

Calling shell functions from another shell script

Hi, I have a query .. i have 2 scripts say 1.sh and 2.sh 1.sh contains many functions written using shell scripts. 2.sh is a script which needs to call the functions definded in 1.sh function calls are with arguments. Can some one tell me how to call the functions from 2.sh? Thanks in... (6 Replies)
Discussion started by: jisha
6 Replies

7. Shell Programming and Scripting

Calling Shell Script

Hello Friends, I have bash script on unix server which i want to call from windows server. Basically i want a command line which will call this script on unix server. Any one has any idea regarding this? Help really appreciated!! Thanks, Roshni. (1 Reply)
Discussion started by: onlyroshni
1 Replies

8. UNIX for Advanced & Expert Users

Calling PL/SQL Script in Shell Programming

Hi all, In a shell script I need to pass two parameters to a pl/sql script and get the ouput of the pl/sql script and use it in shell script. For example Shell script : test.sh PL/SQL script : get_id.sql parameter1 parameter2 Actually get_id.sql has a select statement something... (1 Reply)
Discussion started by: lijju.mathew
1 Replies

9. Programming

Return value (int) from main to calling shell

What is the sytax to return an int from C program main back to calling shell? #!/usr/bin/ksh typeset -i NO_RECS $NO_RECS=process_file # Process file is a C program that is set up to return an int from main. The #program complies with no issues, but an error is generated when the... (3 Replies)
Discussion started by: flounder
3 Replies

10. Shell Programming and Scripting

Calling shell script ?

hi friends, i'm new to unix and straight away i had to start with the script files. I've a script file which gets called from a menu item on a GUI. This script file again calls .awk file, in performing some tasks , which also generates certain files. I modified the files to generate some... (1 Reply)
Discussion started by: Ravi_Kandula
1 Replies
Login or Register to Ask a Question