my case statement doesn't work..

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers my case statement doesn't work..
# 1  
Old 07-10-2002
my case statement doesn't work..

CO UNixware 7.1.1

Hi friends,

I have chopped my case statementt out of my .profile and put it in another script called setsid. The case statement works when run from my .profile but not from my setsid file.

All that the script does is set an environmental variable based on user input. The variable is ORACLE_SID.

Here is my script.
#! /bin/sh

echo "What do you want to set your ORACLE_SID to ?
1: wmsdata
2: wmstest
3: wmsctl"

case "$RESPONSE" in
  export ORACLE_SID
  alias pfile='cd $ORACLE_HOME/admin/wmsdata/pfile/'
  alias bdump='cd $ORACLE_HOME/admin/wmsdata/bdump/'
  alias udump='cd $ORACLE_HOME/admin/wmsdata/udump/'
  export ORACLE_SID
  alias pfile='cd $ORACLE_HOME/admin/wmstest/pfile/'
  alias bdump='cd $ORACLE_HOME/admin/wmstest/bdump/' 
  alias udump='cd $ORACLE_HOME/admin/wmstest/udump/'
  export ORACLE_SID
  alias pfile='cd $ORACLE_HOME/admin/wmsctl/pfile/'
  alias bdump='cd $ORACLE_HOME/admin/wmsctl/bdump/'
  alias udump='cd $ORACLE_HOME/admin/wmsctl/udump/'
  export ORACLE_SID
  alias pfile='cd $ORACLE_HOME/admin/wmsdata/pfile/'
  alias bdump='cd $ORACLE_HOME/admin/wmsdata/bdump/'
  alias udump='cd $ORACLE_HOME/admin/wmsdata/udump/'

The problem is that when I run this script the ORACLE_SID stays the same and does not change.

when I set -vx I notice that th list of commands associated with the reponse do run, yet the variable does not change.

Please help.

Thanks in advance


added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 03:29 PM..
# 2  
Old 07-10-2002
I am new to unix, but i think i can give you a small tip, sometimes tips from stupids makes great history.. LOL

I think that the variable you are setting in your script, is only available for the shell your script is creating, in order to make it available for other shells, I am not sure, but i think you can use EXPORT {variable name} at the end of the script.
# 3  
Old 07-10-2002

RESPONSE is not needed outside of the script.
ORACLE_SID is, which is why it is exported.

exporting RESPONSE does nothing.
# 4  
Old 07-10-2002
majeed73 was kinda on the right track. When your login shell runs your shell script, it creates a child process. Inside that child process you are changing ORACLE_SID. Since it is exported, if that child process was to create any children of its own, those children would see the new ORACLE_SID. But a child cannot affect its parent. When the child process exits, the parent continues with the old value for ORACLE_SID. There is nothing that the child can do to change this. Ditto with your aliases by the way.

Since this stuff was in your .profile, your login shell must also be /bin/sh. The parent could invoke the script as a dotted script. Instead of:
"./script" or "script"
do this:
". ./script" or ". script"

That will cause the script to run in the current shell rather than a subshell. And you should be able to alias that:
alias script=". $HOME/realscript"
or whatever. So now the command "script" would do what you want.
# 5  
Old 07-10-2002
Thankyou very much for your help and explanation, works like a dream.

Again and Again this site never ceases to amaze me!
# 6  
Old 10-25-2002
. ./.profile

I have a similar problem, mine is AIX w/ksh.

I want to be able to 'restart' my login without have to type 'login' to exit and relogin completely to get my .profile to be invoked again.

If I typed, from my $HOME directory, ". ./.profile" (without the quotes of course), the environment variables I set all take effect. However, if I put this command ". ./.profile" in a file call "restart". It doesn't seem to do anything...I am still pointing to the database I first logged in with and the old variables still exist...Here's my restart script..simple enuff:

. ./.profile


. $HOME/.promptuser


export variable1...
export variable2...

Please advise how I can get the "restart" script to export new sets of variables again..right now, it executes and I get the prompt again to pick a database, but regardless of what choice I pick, it still points me back to whatever choice I picked when I first logged in to the server.

Okay, so I am too lazy to type . ./.profile or . $HOME/.profile from the $HOME directory... and want to be able to switch databases on the fly from anywhere that's why I am asking...thanx. It works but it doesn't work.

# 7  
Old 10-25-2002
I believe your problem is that you are running a script and again starting another child process which means the parent does not have any changes.

Try setting up an alias for . ./.profile as follows:

$ alias redo='. ~/restart'
or even better
$ alias redo='. ~/.profile'

Then if you type in redo, you should get your change.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How come this if statement doesn't work?

greetings, the following code isn't working as i expect it to. the first dbl brackets do but the second set gets ignored. ie: if i'm on t70c6n229 it echoes "Something" and i expect it not to. what am i missing? if " ]] || " ]]; then echo "Something" fi thanx! (9 Replies)
Discussion started by: crimso
9 Replies

2. Shell Programming and Scripting

My if statement doesn't work why?

I have the following and for some reason I can't have two options together. I mean if I choose -u and -p it won't work... why? #!/bin/bash resetTime=1 mytotalTime=0 totalHour=0 totalMin=0 averagemem=0 finalaverage=0 times=0 function usage() { cat << EOF USAGE: $0 file EOF } (10 Replies)
Discussion started by: bashily
10 Replies

3. Ubuntu

set completion-ignore-case on doesn't work in bash

completion-ignore-case option doesn't work in my version: /home/user $ echo $BASH_VERSION 3.2.48(1)-release /home/user $ ls -l * -rw-r--r-- 1 user user 0 2009-10-18 00:09 somefile -rw-r--r-- 1 user user 0 2009-10-18 00:09 Somefile /home/user $ set completion-ignore-case on But when I... (2 Replies)
Discussion started by: Sapfeer
2 Replies

4. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

5. Shell Programming and Scripting

my "case" doesn't work !

I'm using the case statement in the following script and it always takes the "*" default choice while it should be "3". I wonder why ??? dt_auj=`date +%d` NBLOG=`ls -al /users/notes01/LOG/t*|awk '{print $7}'|grep $dt_auj|wc -l` case $NBLOG in 1) cat ~/LOG/console-notes > $fic_tmp1 ;; 2)... (5 Replies)
Discussion started by: Nicol
5 Replies

6. UNIX for Dummies Questions & Answers

unmount doesn't work

Hi guys, I've been trying to unmount a floppy like this: unmount /mnt/floppy But then I get a "command not found" message."mount" works,but why not unmount? I've also tried "eject" but all it does is open up my cdrom drive and I tried "eject /mnt/floppy" but I get an error that says Invalid... (2 Replies)
Discussion started by: DISTURBED
2 Replies

7. Shell Programming and Scripting

grep doesn't work within shell script?

I am trying to run the following code from a script file but it complains that syntax of (both instances of) grep is wrong. When I copy and paste it to the terminal, it is OK. Any idea what the problem might be? set i = `grep -c #define flags.h` while ($i>20) @ i-- my func (`cat... (4 Replies)
Discussion started by: barisgultekin
4 Replies

8. UNIX for Dummies Questions & Answers

Repquota doesn't work as Cronjob?!?

Hello: I'm trying to run repquota -ag > /home/usersdir/repquota.txt as a daily cronjob at midnight, but the file always ends up blank. I even tried writing a quick Perl script to e-mail me what running that command outputs, and it's nothing. Can root run repquota as a cronjob? Do I have... (1 Reply)
Discussion started by: b416
1 Replies

9. Windows & DOS: Issues & Discussions

[help]Win98 doesn't respond

My system is combined by Win98 and sco opensever.......but when Win98 is starting .my computer doesn't respond........what can i do? (1 Reply)
Discussion started by: dingxf
1 Replies

10. Programming

why doesn't this work?????

i keep getting the following error with the code segment below when i try to compile the program. parse error before '(' parse error before ')' stray '\' in program this is the code segment and the error is on the second line of the segment #define DEBUG(fmt) if(traceflag) {... (1 Reply)
Discussion started by: token
1 Replies
Login or Register to Ask a Question