LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   BASH script does not work. Do not understand why. (http://www.linuxquestions.org/questions/linux-newbie-8/bash-script-does-not-work-do-not-understand-why-687444/)

SteveInTallyFL 12-01-2008 08:15 AM

BASH script does not work. Do not understand why.
 
This script file is flagged executable and appears to execute when run from the user's home directory (where script is stored) but the environment does not change. What is wrong with this script (RHEL 4)?

#!/bin/bash
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/http_102
export ORACLE_SID=sudstest
export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/opmn/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin

Hangdog42 12-01-2008 08:25 AM

Can I ask why you think the script isn't working? One thing to keep in mind is that if you are running this script from a console, the environment variables are being changed for that console only.

pixellany 12-01-2008 08:27 AM

I'm not clear on how you are testing to see if the environment changes...

You might need quotes, especially here:
export ORACLE_HOME="/u01/app/oracle/product/10.2.0/http_102"

This looks questionable:
export PATH=.:$ORACLE<snipped>
(The leading ".:" seems wrong)

Normally you would add to the PATH using:
export PATH="$PATH:<newstuff>"

Hobbletoe 12-01-2008 09:19 AM

Are you running the script or sourcing the script? If you run it, then any environment variable that you set is set locally, and not carried back to your initial shell. If it is sourced, then once the script finishes, all of the enviroment variables that you changed are carried back to the shell.

You would run the script like this ...

Code:

$ ./my_script.sh
You would source the script like this ...

Code:

$ . ./my_script.sh
or

Code:

$ source ./my_script.sh

SteveInTallyFL 12-01-2008 09:22 AM

Here is hnow I know it did not work
 
Quote:

Originally Posted by Hangdog42 (Post 3360409)
Can I ask why you think the script isn't working? One thing to keep in mind is that if you are running this script from a console, the environment variables are being changed for that console only.

When I echo the $ORACLE_HOME it does not reflect the value in the export statement.

SteveInTallyFL 12-01-2008 09:24 AM

I am running the script
 
Quote:

Originally Posted by Hobbletoe (Post 3360478)
Are you running the script or sourcing the script? If you run it, then any environment variable that you set is set locally, and not carried back to your initial shell. If it is sourced, then once the script finishes, all of the enviroment variables that you changed are carried back to the shell.

You would run the script like this ...

Code:

$ ./my_script.sh
You would source the script like this ...

Code:

$ . ./my_script.sh
or

Code:

$ source ./my_script.sh

I am running the script.

SteveInTallyFL 12-01-2008 09:31 AM

Now that was an AHA moment. . .
 
Quote:

Originally Posted by SteveInTallyFL (Post 3360487)
I am running the script.

Many thanks, Hobbletoe. I need to source these scripts to properly scope the environment variables change. Lesson 1 learned.

Hangdog42 12-01-2008 10:32 AM

One other thing, your PATH statement is destroying any previously set PATH. If that is OK, you can leave it alone, otherwise put the $PATH variable along with the new additions.


All times are GMT -5. The time now is 10:02 AM.