LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 12-01-2008, 08:15 AM   #1
SteveInTallyFL
Member
 
Registered: May 2008
Location: Tallahassee, FL
Distribution: RHEL4, RHEL 5, OEL4, OEL5
Posts: 60

Rep: Reputation: 17
Question 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
 
Old 12-01-2008, 08:25 AM   #2
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,791
Blog Entries: 1

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
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.
 
Old 12-01-2008, 08:27 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
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>"
 
Old 12-01-2008, 09:19 AM   #4
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 10, Linux Mint 11
Posts: 148

Rep: Reputation: 18
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
 
Old 12-01-2008, 09:22 AM   #5
SteveInTallyFL
Member
 
Registered: May 2008
Location: Tallahassee, FL
Distribution: RHEL4, RHEL 5, OEL4, OEL5
Posts: 60

Original Poster
Rep: Reputation: 17
Here is hnow I know it did not work

Quote:
Originally Posted by Hangdog42 View Post
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.
 
Old 12-01-2008, 09:24 AM   #6
SteveInTallyFL
Member
 
Registered: May 2008
Location: Tallahassee, FL
Distribution: RHEL4, RHEL 5, OEL4, OEL5
Posts: 60

Original Poster
Rep: Reputation: 17
I am running the script

Quote:
Originally Posted by Hobbletoe View Post
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.
 
Old 12-01-2008, 09:31 AM   #7
SteveInTallyFL
Member
 
Registered: May 2008
Location: Tallahassee, FL
Distribution: RHEL4, RHEL 5, OEL4, OEL5
Posts: 60

Original Poster
Rep: Reputation: 17
Now that was an AHA moment. . .

Quote:
Originally Posted by SteveInTallyFL View Post
I am running the script.
Many thanks, Hobbletoe. I need to source these scripts to properly scope the environment variables change. Lesson 1 learned.
 
Old 12-01-2008, 10:32 AM   #8
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,791
Blog Entries: 1

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
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.
 
  


Reply

Tags
bash, rhel40, shell script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Root user check in bash script doesn't work tawalker Programming 6 12-18-2011 04:06 AM
Perl Script..Difficult to understand ?? ajeetraina Linux - General 2 02-21-2008 12:17 AM
Help me understand this shell script dwhitney67 Linux - Software 2 10-18-2007 10:02 AM
how to make my code to work on bsd (pptp script on bash) jabka *BSD 1 05-01-2007 01:53 PM
bash script doesnt work in slackware duBeN Linux - Software 1 08-31-2006 12:56 AM


All times are GMT -5. The time now is 04:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration