Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem in Case-switch

Status
Not open for further replies.

appi

IS-IT--Management
Mar 17, 2003
296
CH
Hi Folks,
I know that thgis is a basicly problem and I feel ashamed because I've been searching 2 weeks for the missing point.
I write a shellscript in whch I tried to set variables and want to use this variables in this window. The script works fine inside the script, as I see on the printings, but if this script is over and I asked about env - the variables are not changed.
We're using HP-UX 11.0
The case-tabs are included in the oratab and the grep works fine and correct.
Below's the script:
#########################################################
#!/bin/ksh
DB=$(cat /etc/oratab | grep -v "#" | grep -v '^$' | grep -v "*" | awk -F: '{print $1}')
print "\n\n\nFolgende Datenbanken stehen zur Auswahl\n "$DB
print "\Which DB' ?? "
read inp
case $inp in
ADSYS)
export ORACLE_HOME=/ora1/app/oracle/product/8.0.4
export ORACLE_SID="${inp}"
env | grep ORA
print "\nYou choose " $ORACLE_SID
;;
ASBKP )
ORACLE_HOME=/ora1/app/oracle/product/8.0.4/
ORACLE_SID=$inp
export ORACLE_HOME ORACLE_SID
print "\nYou choose" $ORACLE_SID;;
* ) print "Anything wrong";;
esac

echo "\n\n" $ORACLE_SID
########################################################
The prints inside and outside works fine, both replied the choosen variables, but If I send a new script like env | grep ORA the Variables values the old entries and not the changed.
 
I'm not sure what you're trying to get at, but if I am not mistaken you are trying to set these variables up for your own use when you login. You have to set these variables in your .profile or .kshrc or .cshrc, etc.

If I'm right you can't try to do what you are doing on the fly since you are starting a new process (YOUR_SHELL_SCRIPT) and the trying to get the environment to pick up these variables. The problem is that your process then ends the even if the environment picked up your variables it would lose them since this process is now gone.

For instance: if you type this at the command line:

export TEST="HELLO"
ksh
echo ${TEST}

You will get HELLO back, now if you export another variable in this new shell process:

export TEST1="HELLO1"
echo ${TEST} ${TEST1}

You will get HELLO and HELLO1 back, now exit this new shell process:

exit
echo ${TEST} ${TEST1}

You will only get back HELLO since this process is still active. So if you want your environment variables to have this these updated variables, then it would need to be in your .profile or other environmental file that you might use. Does this help?
 
Hi,
I know that I could set it in my .profile.
What I want to do is to set different values for the same user. So that the user can log on with e.g $TEST and $XY
and if he starts the program he can set via a case-switch to TEST2 or TEST3 even in which environment he wants to come.
The script works during the execution of this script, but whe the script ends yo've the logon-variables.
But I want to have the new setted values, because I want to switch the environments permanent in this shell

regards
Uwe
 
Okay, try this then. When you call the script, use the following syntax before it:

YOUR_PROMPT $> . YOUR_SCRIPT_NAME


The . will spawn the script with your current shell process thus allowing you to keep the updated variables in your shell after the script is finished.
 
pmcmicha,
thanks, this works.
I'd just tested with ./<script> but I forget to use . ./<script> or . <script> to create the subshell.

regards
Uwe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top