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?
# 8  
Old 04-08-2013
Quote:
Originally Posted by PTL
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
PTL,
Skrynesaver and Corona688 both identified one third of your problems. (At least I assume that there is no command named invalid on your system.) You need to combine their suggestions to get rid of the problems they identified in your original script. Try:
Code:
while 1
do
        printf 'Enter  L(Load id), M(Mark id), or E(Exit): '
        read answer
        case "$answer" in
                (E) break;;
                (L) load_id.sh;;
                (M) mark_id.sh;;
                (*) echo 'Invalid choice, try again' >&2
        esac
done

And, I made a few other minor changes:
  1. I changed the first echo to a printf because it is more portable (since the behavior of echo "\c" varies from system to system).
  2. I removed Skrynesaver's clear command since I assume load_id.sh and mark_id.sh produce some output you want to see, and you need to at least be able to see the diagnostic if an invalid choice is entered.
  3. And, assuming that you didn't really want an infinite loop, I added a choice to let the user exit gracefully when they're ready to move on to another task.
I hope this helps.
This User Gave Thanks to Don Cragun For This Post:
# 9  
Old 04-09-2013
Wow!!! Thank you all again! I hadn't realised there were responses waiting for me, I was busy trying various other options.

You were all correct i.e. bits from each suggestion put together seem to have given me what I wanted. I used a while loop and I took out the 'exec' from the called script. The modification I had made before was to replace the exec with '.' which apparently was doing the same as 'exec' and hence no good. So what I have now done is to call the load_id.sh etc without 'exec' or '.'

thanks again. Hopefully that should be it.

PTL
# 10  
Old 04-09-2013
Quote:
Originally Posted by PTL
The modification I had made before was to replace the exec with '.' which apparently was doing the same as 'exec'
It does something very different, actually.

With exec, the running program that calls the other script ceases to exist... There is nothing left to return to.

With ., your shell still exists, but a new one is not made... The new script is run literally inside the old as if the code had been typed right inside it. When it hits exit, it kills your shell.

When you run it without exec or . it creates a whole new shell to run it in, which dies without killing your original one.

Since you didn't post your code, I never guessed what you did. Please always post your code.
# 11  
Old 04-10-2013
Hi Don,
The point you made about portability of "\c" is interesting. How do I get the cursor to go on to the next line i.e. what is the replacement for "\c" when I use printf?
I have indeed noticed that "\c" on our systeem, while it moves the cursor to the next line (which I want), displays itself as well which I don't really want.

thanks
PTL
# 12  
Old 04-10-2013
Quote:
Originally Posted by PTL
Hi Don,
The point you made about portability of "\c" is interesting. How do I get the cursor to go on to the next line i.e. what is the replacement for "\c" when I use printf?
I have indeed noticed that "\c" on our systeem, while it moves the cursor to the next line (which I want), displays itself as well which I don't really want.

thanks
PTL
By convention, when you print a prompt, you should leave the cursor at the end of the prompt and let the user's response provide the trailing newline character that will move the cursor to the next line.

On UNIX Systems, echo recognizes several backslash escapes including:
\a alert (screen flash or bell character or both)
\b backspace character
\f form feed character
\t tab character
\n newline character
\c stop looking for more text and skip trailing newline
and accepts no options. Any arguments starting with a - will be printed as is.

On BSD Systems, echo does not treat backslash as special, but has a -n option that will skip the trailing newline. Any other operands that look like options will be printed as is.

The standards allow either the BSD or the UNIX System behavior.

On Linux Systems, echo provides several options that are not allowed by the standards. Some of them recognize backslash escapes; some of them don't. Some of them skip the trailing newline; some don't.

Given the command:
Code:
echo -n -x -- "a\tb: \c"

A UNIX System (except OS X) will produce:
Code:
-n -x -- a	b: >>>Cursor here<<<

while a BSD System will produce:
Code:
-x -- a\tb: \c>>>Cursor here<<<

and a Linux System will do something different from either of the above.
A bug in OS X (which is supposed to be a UNIX System) prints the \t instead of replacing it with a tab.

As has been said many times in these forums before, if any of the operands to echo start with a minus sign or contain a backslash character, use printf instead of echo if you want to write a portable script.

PS The format operand to printf recognizes all of the normal C printf() backslash escapes. So, \n in the format string prints a newline.
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