Updating environment variables | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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 !!

Updating environment variables

UNIX for Dummies Questions & Answers


Tags
environment variables, java

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-23-2010
jtennent jtennent is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 24 August 2010, 1:20 PM EDT
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Question Updating environment variables

ok, this definitely falls in the n00b category... I'm trying to upgrade Java on my server and just need to update the PATH, CLASSPATH, and JAVA_HOME environment variables.

This is what they currently are:
PATH=/usr/local/jdk1.5.0_15//bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/java/bin:/usr/local/ant/bin:/root/bin
JAVA_HOME=/usr/local/jdk1.5.0_15/
CLASSPATH=/usr/local/jdk1.5.0_15//jre/lib

This is my java install directories under /usr/local:
4 drwxr-xr-x 9 root root 4096 Sep 19 2008 jdk1.5.0_15
4 drwxr-xr-x 10 root root 4096 Sep 23 2008 jdk1.6.0_07
0 lrwxrwxrwx 1 root root 11 Sep 23 2008 java -> jdk1.6.0_07

And this is the java that is being used:
[root@dev local]# which java
/usr/local/jdk1.5.0_15/bin/java

I looked at my /etc/bashrc and it is calling /etc/profile.d/java.sh, which looks like this:
export JAVA_HOME=/usr/local/java
export ANT_HOME=/usr/local/ant
export PATH=$PATH:$JAVA_HOME/bin:$ANT_HOME/bin

What's confusing me is that I can see that the java.sh is indeed running but things aren't working out properly.
1) I can see the java.sh appends the last 2 entries of the PATH shown above. But the first entry in the path goes to the jdk1.5 with a double //bin.
2) JAVA_HOME does not point to /usr/local/java but to /usr/local/jdk1.5.0_15/

Any ideas how to figure this out?

Thanks!
Sponsored Links
    #2  
Old 08-23-2010
agama agama is offline Forum Advisor  
Always Learning
 
Join Date: Jul 2010
Last Activity: 7 April 2014, 3:02 PM EDT
Location: earth>US>UTC-5
Posts: 1,466
Thanks: 110
Thanked 506 Times in 485 Posts
Quote:
I looked at my /etc/bashrc and it is calling /etc/profile.d/java.sh, which looks like this:
Im going to assume that by 'calling' you mean that the entry in bashrc looks like this:


Code:
/etc/profile.d/java.sh

If that is the case, then you need to source the java.sh rather than executing it:


Code:
. /etc/profile.d/java.sh

That's a leading dot then a space.

When you export a variable in a script, it is placed into the environment, but is 'visible' only to that script and any processes that the script invokes. Environment variables don't/cannot perk back up to the parent process. If you are indeed invoking java.sh this is what is happening.

By sourcing the file, you are executing the commands in java.sh as though they existed in the current file, .bashrc in this case. This has the effect of setting the environment variables for the current shell as you desire.
Sponsored Links
    #3  
Old 08-23-2010
jtennent jtennent is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 24 August 2010, 1:20 PM EDT
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
ok, here's the contents of my bashrc. It's a little long. The part where it references the java.sh, or actually ./profile.d/*.sh is at the bottom:


Code:
# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# By default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ $UID -gt 99 ] && [ "`id -gn`" = "`id -un`" ]; then
        umask 002
else
        umask 022
fi

# are we an interactive shell?
if [ "$PS1" ]; then
    case $TERM in
        xterm*)
                if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
                else
                PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
                fi
                ;;
        screen)
                if [ -e /etc/sysconfig/bash-prompt-screen ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
                else
                PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"'
                fi
                ;;
        *)
                [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
            ;;

    esac
    # Turn on checkwinsize
    shopt -s checkwinsize
    [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
fi

if ! shopt -q login_shell ; then # We're not a login shell
        # Need to redefine pathmunge, it get's undefined at the end of /etc/profile
    pathmunge () {
                if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
                        if [ "$2" = "after" ] ; then
                                PATH=$PATH:$1
                        else
                                PATH=$1:$PATH
                        fi
                fi
        }

        for i in /etc/profile.d/*.sh; do
                if [ -r "$i" ]; then
                        . $i
        fi
        done
        unset i
        unset pathmunge
fi
# vim:ts=4:sw=4

    #4  
Old 08-23-2010
agama agama is offline Forum Advisor  
Always Learning
 
Join Date: Jul 2010
Last Activity: 7 April 2014, 3:02 PM EDT
Location: earth>US>UTC-5
Posts: 1,466
Thanks: 110
Thanked 506 Times in 485 Posts
The commands are being source, but only if the shell is not a login (interactive) shell.


Code:
 if ! shopt -q login_shell ; then # We're not a login shell 
        # Need to redefine pathmunge, it get's undefined at the end of /etc/profile
    pathmunge () {
                if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
                        if [ "$2" = "after" ] ; then
                                PATH=$PATH:$1
                        else
                                PATH=$1:$PATH
                        fi
                fi
        }

        for i in /etc/profile.d/*.sh; do
                if [ -r "$i" ]; then
                        . $i
        fi
        done
        unset i
        unset pathmunge
fi

If you don't have a .profile or .bash_profile in your home directory, create one and add the single line to source the file. If you do have one, most do, edit it to add the command:


Code:
. /etc/profile.d/java.sh

The Following User Says Thank You to agama For This Useful Post:
jtennent (08-24-2010)
Sponsored Links
    #5  
Old 08-24-2010
jtennent jtennent is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 24 August 2010, 1:20 PM EDT
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks, that was it!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
using environment variables lassimanji Shell Programming and Scripting 2 04-29-2009 03:58 PM
environment variables radhika03 Shell Programming and Scripting 3 01-22-2007 01:58 PM
environment variables sumsin Programming 6 03-13-2006 11:17 AM
help..Environment variables... sekar sundaram UNIX for Dummies Questions & Answers 3 08-30-2005 04:35 AM
environment variables spavlov UNIX for Dummies Questions & Answers 3 08-20-2003 10:49 AM



All times are GMT -4. The time now is 01:25 AM.