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 06-27-2006, 12:43 PM   #1
caesarkim
Member
 
Registered: Nov 2003
Posts: 32

Rep: Reputation: 15
updating environment variables


i updated one of the environment variables, PATH. but I don't know how to keep it in my environment variables list. i mean when I close the session, it's gone.

I am using red-hat linux.

is there any way to do it?

Thanks.
 
Old 06-27-2006, 12:49 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
If you are using bash, you can add the extra PATH elements in your ~/.bash_profile

PATH=$PATH":your/new/directory/here"

--- rod.
 
Old 06-27-2006, 12:55 PM   #3
caesarkim
Member
 
Registered: Nov 2003
Posts: 32

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by theNbomr
If you are using bash, you can add the extra PATH elements in your ~/.bash_profile

PATH=$PATH":your/new/directory/here"

--- rod.

Thanks for the reply.

I edited the file in vi mode.

export PATH='/java/bin:$PATH'


but when I check ('env'), it doesn't show the updated one.

is there any command after I save the bash_profile? cuz i remember that i did something in unix something like ". .profile".

can anybody tell me what it is?


Thanks.
 
Old 06-27-2006, 01:33 PM   #4
dosnlinux
Member
 
Registered: Mar 2005
Distribution: slackware 11, arch 2007.08
Posts: 154

Rep: Reputation: 30
try
Code:
source ~/.bash_profile
 
Old 06-27-2006, 01:37 PM   #5
caesarkim
Member
 
Registered: Nov 2003
Posts: 32

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by dosnlinux
try
Code:
source ~/.bash_profile

I got the following error.

"if: Expression Syntax."...


here is my profile.

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

JAVA_HOME='/java'

PATH=$JAVA_HOME/bin:$PATH
 
Old 06-27-2006, 02:02 PM   #6
Daws
Member
 
Registered: May 2006
Location: UK
Distribution: Debian
Posts: 448

Rep: Reputation: 37
Code:
PATH=$PATH:$HOME/bin
 
 JAVA_HOME='/java'
 
 PATH=$JAVA_HOME/bin:$PATH
using $PATH when setting a new PATH is fine if there already is a PATH, but you cannot use $PATH if no previous PATH is set eg when you source ~/.bash_profile or login.

**EDIT**

Upon rereading: Did anyone understand what I just said?

**EDIT**

Remove both PATH lines and replace it with one for simplicity:

Code:
PATH=$ORIGINAL_PATH:$HOME/bin:$JAVA_HOME/bin
$ORIGINAL_PATH is what your path was set to before you made any changes
for me this is

Code:
 /bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/games
It may be different for RedHat

Last edited by Daws; 06-27-2006 at 02:03 PM.
 
Old 06-27-2006, 02:20 PM   #7
caesarkim
Member
 
Registered: Nov 2003
Posts: 32

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Daws
Code:
PATH=$PATH:$HOME/bin
 
 JAVA_HOME='/java'
 
 PATH=$JAVA_HOME/bin:$PATH
using $PATH when setting a new PATH is fine if there already is a PATH, but you cannot use $PATH if no previous PATH is set eg when you source ~/.bash_profile or login.

**EDIT**

Upon rereading: Did anyone understand what I just said?

**EDIT**

Remove both PATH lines and replace it with one for simplicity:

Code:
PATH=$ORIGINAL_PATH:$HOME/bin:$JAVA_HOME/bin
$ORIGINAL_PATH is what your path was set to before you made any changes
for me this is

Code:
 /bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/games
It may be different for RedHat










so I changed like this. it has only PATH. But it still returns the same error.

-----------------------------------------------------------------
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$HOME/bin
 
Old 06-27-2006, 02:24 PM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
Just so that you understand, the ~/.bash_profile is run when you log in. You want this for changes in the PATH variable, because if you used ~/.bashrc, you will be re-adding things to your PATH variable everytime a new shell is opened.
Quote:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
This looks fine to me. But double check that there is a space inside the square brackets. While '[' is a builtin, it is also a command in /bin/ and the space is needed. Also check that your default shell is "/bin/bash". If it isn't then sourcing ~/.profile may fail.
 
Old 06-27-2006, 02:35 PM   #9
caesarkim
Member
 
Registered: Nov 2003
Posts: 32

Original Poster
Rep: Reputation: 15
here is my whole profile. I commented out all variables. I have only if statement. it still fails with or without "#!/bin/bash".


#!/bin/bash

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
 
Old 06-27-2006, 02:39 PM   #10
Daws
Member
 
Registered: May 2006
Location: UK
Distribution: Debian
Posts: 448

Rep: Reputation: 37
Could you post your ~/.bashrc for us
 
Old 06-27-2006, 02:48 PM   #11
caesarkim
Member
 
Registered: Nov 2003
Posts: 32

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Daws
Could you post your ~/.bashrc for us

Here it is...


------------------------------------------

. /etc/skel/bashrc-DEFAULT
# Add customizations below this line

# Default Local Timezone set to PST8PDT
# uncomment out the entry below to change it
#
#export TZ=CST6CDT
 
Old 06-27-2006, 04:15 PM   #12
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Are you actually using 'bash'? There are other shells, csh and kin in particular, that don't have the same scripting language.

Try
Code:
echo $SHELL
If you are using bash, you need to either login or

Code:
source .bash_profile
You say it bugs out when you try to source it. Do you also get an error when you login?

Just looking at your second post (first reply), you have enclosed everything in your assignment to PATH in single quotes. This will prevent the expansion of the existing PATH variable. Use the syntax I used in my example.

--- rod.

Last edited by theNbomr; 06-27-2006 at 04:20 PM.
 
Old 06-27-2006, 04:21 PM   #13
caesarkim
Member
 
Registered: Nov 2003
Posts: 32

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by theNbomr
Are you actually using 'bash'? There are other shells, csh and kin in particular, that don't have the same scripting language.

Try
Code:
echo $SHELL
If you are using bash, you need to either login or

Code:
source .bash_profile
You say it bugs out when you try to source it. Do you also get an error when you login?

--- rod.


when I execute echo $SHELL, I got "/bin/csh". How can I change it to bash?

sorry.. i am a newbie for linux.
 
Old 06-27-2006, 04:23 PM   #14
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Find your entry in /etc/passwd. As root, change from /bin/csh to /bin/bash

I'm pretty sure this won't apply to you, but just for completeness, you may need/want to copy stuff from your ~/.cshrc file to the new .bashrc &/or .bash_profile. Of course you'd have to modify the scripting as necessary.

--- rod.

Last edited by theNbomr; 06-27-2006 at 04:28 PM.
 
  


Reply


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
Environment Variables - where do they go!?! iansoundz Linux - General 7 11-17-2005 03:27 AM
environment variables naren Linux - Software 1 12-15-2004 07:44 AM
when to use environment variables? mark_2811 Programming 2 02-23-2004 07:09 PM
environment variables moeminhtun Linux - General 4 01-15-2003 10:50 AM
environment variables aethereal Linux - Newbie 7 12-19-2001 10:34 AM


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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration