The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!


Other UNIX.COM Threads You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3) sandiworld HP-UX 2 10-25-2007 07:39 AM
unmount doesn't work DISTURBED UNIX for Dummies Questions & Answers 2 07-04-2002 03:14 PM
grep doesn't work within shell script? barisgultekin Shell Programming and Scripting 4 05-24-2002 11:01 AM
Repquota doesn't work as Cronjob?!? b416 UNIX for Dummies Questions & Answers 1 04-14-2002 05:44 PM
why doesn't this work????? token High Level Programming 1 09-20-2001 07:08 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-10-2002
Registered User
 

Join Date: Sep 2001
Location: UK
Posts: 25
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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.
Code:
#! /bin/sh

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

case "$RESPONSE" in
1)
  ORACLE_SID=wmsdata
  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/'
  ;;
2)
  ORACLE_SID=wmstest
  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/'
  ;;
3)
  ORACLE_SID=wmsctl
  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/'
  ;;
*)
  ORACLE_SID=wmsdata
  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/'
  ;;
esac
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

Suresh

added code tags for readability --oombera

Last edited by oombera : 02-19-2004 at 11:29 AM.
Forum Sponsor
  #2 (permalink)  
Old 07-10-2002
Registered User
 

Join Date: Jul 2002
Location: Dubai - UAE
Posts: 5
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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 (permalink)  
Old 07-10-2002
Registered User
 

Join Date: Sep 2001
Location: UK
Posts: 25
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
HI,

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

exporting RESPONSE does nothing.
  #4 (permalink)  
Old 07-10-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,205
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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 (permalink)  
Old 07-10-2002
Registered User
 

Join Date: Sep 2001
Location: UK
Posts: 25
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Thankyou very much for your help and explanation, works like a dream.

Again and Again this site never ceases to amaze me!
Google UNIX.COM
Closed Thread



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 08:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102