LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   updating environment variables (https://www.linuxquestions.org/questions/linux-newbie-8/updating-environment-variables-458805/)

caesarkim 06-27-2006 11:43 AM

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.

theNbomr 06-27-2006 11:49 AM

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

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

--- rod.

caesarkim 06-27-2006 11:55 AM

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.

dosnlinux 06-27-2006 12:33 PM

try
Code:

source ~/.bash_profile

caesarkim 06-27-2006 12:37 PM

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

Daws 06-27-2006 01:02 PM

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

caesarkim 06-27-2006 01:20 PM

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

jschiwal 06-27-2006 01:24 PM

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.

caesarkim 06-27-2006 01:35 PM

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

Daws 06-27-2006 01:39 PM

Could you post your ~/.bashrc for us

caesarkim 06-27-2006 01:48 PM

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

theNbomr 06-27-2006 03:15 PM

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.

caesarkim 06-27-2006 03:21 PM

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.

theNbomr 06-27-2006 03:23 PM

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.


All times are GMT -5. The time now is 10:13 PM.