LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Adding to the $PATH (https://www.linuxquestions.org/questions/linux-newbie-8/adding-to-the-%24path-115874/)

chri5 11-14-2003 03:33 AM

Adding to the $PATH
 
Hello,
I would like to add to the system wide $PATH in red hat 9.
Which file should I edit to achive this?

Examples would be appreciated!

Thanks,
Chris.

slakmagik 11-14-2003 03:42 AM

In Slack it's /etc/profile - that much *should* be the same in RH.

chri5 11-14-2003 03:51 AM

ok my /etc/profile

looks like this:-
-------------------------------------
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}

# Path manipulation
if [ `id -u` = 0 ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi

pathmunge /usr/X11R6/bin after

unset pathmunge

# No core files by default
ulimit -S -c 0 > /dev/null 2>&1

USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"

HOSTNAME=`/bin/hostname`
HISTSIZE=1000

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

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

unset i
---------------------------------------

Where and how would I place additions to the system wide $PATH into the above /etc/profile ?

Thanks,
Chris

Y0jiMb0 11-14-2003 03:52 AM

Quote:

In Slack it's /etc/profile - that much *should* be the same in RH.
in mandrake too ;)
example:
Code:

export PATH=$PATH:/usr/games
adds /usr/games to the path environment variable.
adding to /etc/profile the next
Code:

if ! echo ${PATH} |grep -q /usr/games ; then
    PATH="$PATH:/usr/games"
fi

could be useful if you want this directory always in your path.
Take a look at /etc/profile, you maybe have more clues there...
Regards

chri5 11-14-2003 04:10 AM

There are many directories in my $PATH:-

bash: /usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/bo1cps/bin: No such file or directory

Some of these do not appear in the /etc/profile

Where are these directories coming from?

Would it be ok to add:-

if ! echo ${PATH} |grep -q /usr/games ; then
PATH="$PATH:/usr/games"
fi

anywhere in the /etc/profile ?

Thanks,
Chris.

Y0jiMb0 11-14-2003 04:25 AM

Quote:

Would it be ok to add:-

if ! echo ${PATH} |grep -q /usr/games ; then
PATH="$PATH:/usr/games"
fi

anywhere in the /etc/profile ?
I thin so; here you have my /etc/prfiles, just in case...
Code:

# /etc/profile -*- Mode: shell-script -*-
# (c) MandrakeSoft, Chmouel Boudjnah <chmouel@mandrakesoft.com>

loginsh=1

# Users generally won't see annoyng core files
[ "$UID" = "0" ] && ulimit -S -c 1000000 > /dev/null 2>&1

if ! echo ${PATH} |grep -q /usr/X11R6/bin ; then
    PATH="$PATH:/usr/X11R6/bin"
fi

if [ "$UID" -ge 500 ] && ! echo ${PATH} |grep -q /usr/games ; then
    export PATH=$PATH:/usr/games
fi

umask 022

USER=`id -un`
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
HISTCONTROL=ignoredups
HOSTNAME=`/bin/hostname`
HISTSIZE=1000

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
    INPUTRC=/etc/inputrc
fi

# some old programs still use it (eg: "man"), and it is also
# required for level1 compliance for LI18NUX2000
NLSPATH=/usr/share/locale/%l/%N

export PATH PS1 USER LOGNAME MAIL HOSTNAME INPUTRC NLSPATH
export HISTCONTROL HISTSIZE

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

unset i

Regards

slakmagik 11-14-2003 04:31 AM

Quote:

Originally posted by chri5
Where are these directories coming from?

I hesitate to say with RH but some path definition comes from /etc/profile, some from your various bash initialization scripts. Maybe other places.

Yeesh. RH scripts are ugly. ;)

chri5 11-14-2003 04:44 AM

Quote:

Originally posted by digiot
Yeesh. RH scripts are ugly. ;)
I'll second that! Thanks for eveyones help...

Skyline 11-14-2003 10:38 AM

........... or more simply (for example)

PATH=$PATH:/home/john/programs

export PATH

If you now check your PATH with

echo $PATH

you'll see the new directory at the end of the colon separated list of directories in your PATH variable.


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