Re: Interactive Scripts, return codes

From: Icarus Sparry <ccsis_at_bath.ac.uk>
Date: 1997/06/06
Message-ID: <EBCLtw.GM0.C.amo_at_bath.ac.uk>#1/1


In article <339703AA.9D0_at_mb.sympatico.ca>, Programming <sysdev_at_mb.sympatico.ca> wrote:
>Interactive scripts in Unix.
>Return codes from Oracle, or Unix.
>
>I want to run a script in Unix,
>that will call
>1) Oracle sqlplus
>2) Oracle sqlloader
>3) Oracle sqlplus.
>exit
>
>
>At certain points in the script,
>I want to ask the user different
>questions, and accept Yes or No responses.
>How can I accomplish this, or,
>what is the command to do this?

You use 'read reply' to get a line of input from the user. You use 'case' to look at the value. Something like this

echo 'Do you want me to exit?'
while read reply
do

	case "$reply" in
		YES|Yes|yes|Y|y) reply=y; break;;
		NO|No|no|n) reply=n; break;;
	esac
	echo 'Please answer the question yes or no.'
done
# At this point "$reply" is either y, n or nothing, the latter case if the # user typed EOF.

>The other thing that I want to do,
>is to check the return codes from
>Oracle, and abort if the commands
>failed. How can this be accomplished?

The exit status of a command is available in the $? variable, but often you can say

if oracleplus ......
then

        # It worked
else

	echo It all went wronf >&2
	exit 99

fi

>How could I branch to another part of
>the script?

These days the name of the game is 'structured programming', so you use 'if .. then ... else ... fi' and 'while .... do .... done' constructs. Modern shells have functions in them as well.

>Would the return code be from Unix,
>or from Oracle?

From Oracle.

Icarus Received on Fri Jun 06 1997 - 00:00:00 CEST

Original text of this message