From: djehres on
Can someone please tell me you this case statement is not exporting my
environment variables?


#!/usr/bin/ksh

if [ $# -ne 2 ]
then
echo
echo Usage: \. setdb.sh SID VERS
echo
exit 1
fi

ORACLE_SID=$1
ORACLE_VERS=$2


case "$ORACLE_VERS" in



'9.2') ORACLE_BASE=/apps/oracle9i
echo "hello"
ORACLE_HOME=/apps/oracle9i/product/9.2.0
ORACLE_SID=orcl9i

PATH=$ORACLE_HOME/bin:/bin:/sbin:/usr/bin:/usr/ccs/bin:/usr/local/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH
;;

'10.2') export ORACLE_BASE=/apps/oracle
echo "hello 10g"
export ORACLE_HOME=/apps/oracle/product/10.2.0
export ORACLE_SID=orcl
export
PATH=$ORACLE_HOME/bin:/bin:/sbin:/usr/bin:/usr/ccs/bin:/usr/local/bin
;;

*)
;;
esac


echo ORACLE_SID = $ORACLE_SID
echo ORACLE_VERS = $ORACLE_VERS

exit 0

[oracle(a)host] /apps/oracle$ ./setdb.ksh orcl 10.2
hello 10g
ORACLE_SID = orcl
ORACLE_VERS = 10.2

[oracle(a)host] /apps/oracle$ ./setdb.ksh orcl9i 9.2
hello
ORACLE_SID = orcl9i
ORACLE_VERS = 9.2
[oracle(a)cpr1dss] /apps/oracle$


You can see it enters each option by the echo it prints out. It just
does not export the vars. I have tried two different ways to export
the vars, as you can see. This is the Korn Shell on Sun Solaris 8.

thanks.

From: William on
"djehres" <david_ehresmann(a)raytheon.com> wrote in message
news:1144251087.870092.313680(a)g10g2000cwb.googlegroups.com...
> Can someone please tell me you this case statement is not exporting my
> environment variables?

It looks like it is working to me.

You're not expecting it to set variables in your
current environment, are you? It can't do that
since a child process can't alter the parent's
environment. (Export makes them avialable to the
children of the script's process.)

To do that, you need to "source" it - which
executes the script in the current process as
though you'd typed it in. (And not all shells
allow command line arguments for sourced files.)

An alternative to sourcing it, is to have it emit
commands in the correct syntax for your shell
via stdout and eval those commands:
eval `./thescript`

-Wm


From: Hajo Ehlers on

djehres wrote:
> Can someone please tell me you this case statement is not exporting my
> environment variables?
>
>
snip valid script

It does but since you finished the script all variables created by the
subprocess ( the script ) are gone.

So your cuurent shell should source the file and not executing it.

Example:

cat ./MyVar
#!/usr/bin/ksh
export MyVar=$1
echo MyVar = $MyVar

echo MyVar = $MyVar
../MyVar 1234 ; echo MyVar = $MyVar # Execute the script ( new
subprocess )
.. ./MyVar 4321 ; echo MyVar = $MyVar # Source the script ( current
process )
../MyVar 5678 ; echo MyVar = $MyVar # Execute the script ( new
subprocess )

hth
Hajo

From: Miles on
To run a script and have the environment varibles persist after it is
done, run the script with a <dot><space> in front of it.

I do a similar thing for Sybase:
###################################################################################
# Start
###################################################################################
if [[ $SYBASE_VERSION = "1252" ]]
then
. /home/unxsa/bin/export1252

elif [[ $SYBASE_VERSION = "1251" ]]
then
. /home/unxsa/bin/export1251

elif [[ $SYBASE_VERSION = "1250" ]]
then
. /home/unxsa/bin/export1250

elif [[ $SYBASE_VERSION = "1200" ]]
then
. /home/unxsa/bin/export1200

else
echo "ERROR: Unknown Sybase version: $SYBASE_VERSION"

fi