View previous topic :: View next topic |
Author |
Message |
kcy29581 Apprentice


Joined: 04 Nov 2004 Posts: 284 Location: England
|
Posted: Thu May 26, 2005 3:31 pm Post subject: how to properly add things to my PATH variable? |
|
|
Hi all,
When guides like the ccache one in the Gentoo dos and others say you should add a path to your PATH variable, whats the best fool-proof way? I mean there are several instances where PATH is given a value in /etc/profile and there is a point where "export PATH" appears. Do I have to make sure my PATH is altered before the export bit?
As an example to help me out lets say I need to add /usr/games/bin to my PATH. I will show my /etc/profile and you can tell me what to do.
Thanks in advance!
Code: | # /etc/profile:
# $Header: /var/cvsroot/gentoo-src/rc-scripts/etc/profile,v 1.28.4.3 2005/04/29 03:34:01 vapier Exp $
#
# That this file is used by any Bourne-shell derivative to setup the
# environment for login shells.
# Load environment settings from profile.env, which is created by
# env-update from the files in /etc/env.d
if [[ -e /etc/profile.env ]] ; then
. /etc/profile.env
fi
# 077 would be more secure, but 022 is generally quite realistic
umask 022
# Set up PATH depending on whether we're root or a normal user.
# There's no real reason to exclude sbin paths from the normal user,
# but it can make tab-completion easier when they aren't in the
# user's PATH to pollute the executable namespace.
#
# It is intentional in the following line to use || instead of -o.
# This way the evaluation can be short-circuited and calling whoami is
# avoided.
if [[ "$EUID" == 0 ]] || [[ "$USER" == "root" ]] ; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${ROOTPATH}"
else
PATH="/usr/local/bin:/usr/bin:/bin:${PATH}"
fi
export PATH
unset ROOTPATH
# Extract the value of EDITOR
[[ -z $EDITOR ]] && EDITOR=$(. /etc/rc.conf 2>/dev/null; echo $EDITOR)
[[ -z $EDITOR ]] && EDITOR="/bin/nano"
export EDITOR
if [[ -n ${BASH_VERSION} ]] ; then
# Newer bash ebuilds include /etc/bash/bashrc which will setup PS1
# including color. We leave out color here because not all
# terminals support it.
if [[ -f /etc/bash/bashrc ]] ; then
# Bash login shells run only /etc/profile
# Bash non-login shells run only /etc/bash/bashrc
# Since we want to run /etc/bash/bashrc regardless, we source it
# from here. It is unfortunate that there is no way to do
# this *after* the user's .bash_profile runs (without putting
# it in the user's dot-files), but it shouldn't make any
# difference.
. /etc/bash/bashrc
else
PS1='\u@\h \w \$ '
fi
else
# Setup a bland default prompt. Since this prompt should be useable
# on color and non-color terminals, as well as shells that don't
# understand sequences such as \h, don't put anything special in it.
PS1="$(whoami)@$(uname -n | cut -f1 -d.) \$ "
fi
|
_________________ There is no spoon...
Oh, and it's WINDOWS not Winblowz for those who can't spell |
|
Back to top |
|
 |
numerodix l33t


Joined: 18 Jul 2002 Posts: 743 Location: nl.eu
|
Posted: Thu May 26, 2005 4:41 pm Post subject: |
|
|
You should look at the files under /etc/env.d, that's where environmental variables are set.  _________________ undvd - ripping dvds should be as simple as unzip |
|
Back to top |
|
 |
dwblas Guru

Joined: 14 Jul 2003 Posts: 525 Location: Southern California (No jokes please)
|
Posted: Thu May 26, 2005 7:28 pm Post subject: |
|
|
I use ~/.bashrc like this
export PATH=$PATH:/path_to_add |
|
Back to top |
|
 |
Deepak420 Apprentice


Joined: 12 Jan 2005 Posts: 173 Location: Beantown
|
Posted: Thu May 26, 2005 8:42 pm Post subject: |
|
|
.bashrc is the proper place to do this for a single user. If you want to change the path for root or for all non-root users you should change:
Code: | if [[ "$EUID" == 0 ]] || [[ "$USER" == "root" ]] ; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${ROOTPATH}"
else
PATH="/usr/local/bin:/usr/bin:/bin:${PATH}"
fi |
Where the path after the "if [[ "$EUID" == 0 ]] || [[ "$USER" == "root" ]]" will affect root, and the lower path will affect all users. |
|
Back to top |
|
 |
kcy29581 Apprentice


Joined: 04 Nov 2004 Posts: 284 Location: England
|
Posted: Thu May 26, 2005 8:44 pm Post subject: |
|
|
great. thanks for that tip. just needed to hear someone say that!  _________________ There is no spoon...
Oh, and it's WINDOWS not Winblowz for those who can't spell |
|
Back to top |
|
 |
ryker Guru


Joined: 28 May 2003 Posts: 412 Location: Portage, IN
|
Posted: Thu May 26, 2005 9:33 pm Post subject: |
|
|
I was wondering this also, and I'm having a problem.
I'm adding a bunch of environment variables for all users and I also need to add to the path variable. I read the environment variable guide and it says not to modify /etc/profile but to add a file in /etc/env.d.
So I created a file in /etc/env.d named 100local and added everything to it. I then ran env-update && /etc/profile and all of the new vars from 100local were added, but the PATH var wasn't modified.
Why?
Here's my 100local file contents: Code: | PATH="/opt/gridengine/bin/lx26-x86"
SGE_ROOT="/opt/gridengine"
ARCH=/opt/gridengine/util/arch
DEFAULTMANPATH="i686"
MANTYPE="i686"
SGE_CELL="ME"
SGE_QMASTER_PORT=701
MANPATH=$SGE_ROOT/$MANTYPE:$MANPATH
PATH=$SGE_ROOT/bin/$ARCH:$PATH
shlib_path_name="i686"
shlib_path_name=$ARCH
|
Also, can I ran bash commands in this 100local file?
For example: Code: | old_value=`eval echo '$'$shlib_path_name`
if [ x$old_value = x ]; then
eval $shlib_path_name=$SGE_ROOT/lib/$ARCH
else
eval $shlib_path_name=$SGE_ROOT/lib/$ARCH:$old_value
fi
|
_________________ Athlon 64 3200+, 80G WD sata hd + 200G IDE, 1G Geil DDR400, MSI K8T Neo
IntelCore2Duo 2.0Ghz MSI laptop,100G SATA hd, 2G RAM |
|
Back to top |
|
 |
numerodix l33t


Joined: 18 Jul 2002 Posts: 743 Location: nl.eu
|
Posted: Fri May 27, 2005 2:43 pm Post subject: |
|
|
ryker wrote: | I was wondering this also, and I'm having a problem.
I'm adding a bunch of environment variables for all users and I also need to add to the path variable. I read the environment variable guide and it says not to modify /etc/profile but to add a file in /etc/env.d.
So I created a file in /etc/env.d named 100local and added everything to it. I then ran env-update && /etc/profile and all of the new vars from 100local were added, but the PATH var wasn't modified.
Why?
|
Hm, what about setting the PATH in 00basic? That one already has an entry for it...
ryker wrote: | Also, can I ran bash commands in this 100local file?
For example: Code: | old_value=`eval echo '$'$shlib_path_name`
if [ x$old_value = x ]; then
eval $shlib_path_name=$SGE_ROOT/lib/$ARCH
else
eval $shlib_path_name=$SGE_ROOT/lib/$ARCH:$old_value
fi
|
|
I doubt it.. I think you'll just get syntax errors. _________________ undvd - ripping dvds should be as simple as unzip |
|
Back to top |
|
 |
ryker Guru


Joined: 28 May 2003 Posts: 412 Location: Portage, IN
|
Posted: Fri May 27, 2005 4:22 pm Post subject: |
|
|
OK. I'm really confused. I tried appending something to the PATH variable in /etc/env.d/00basic and it didn't do anything. I ran env-update && source /etc/profile after I changed it. I also added a variable 'CRAP="Real Crap" at the same time. My new CRAP varialbe showed up but PATH was not changed!
I tried this on 2 differnt machines with the same results.
BTW, changing the PATH variable in /etc/profile worked just fine. But, don't I have to worry about an emerge sync wiping out my default profile if there is some kind of change in the future? _________________ Athlon 64 3200+, 80G WD sata hd + 200G IDE, 1G Geil DDR400, MSI K8T Neo
IntelCore2Duo 2.0Ghz MSI laptop,100G SATA hd, 2G RAM |
|
Back to top |
|
 |
kcy29581 Apprentice


Joined: 04 Nov 2004 Posts: 284 Location: England
|
Posted: Fri Jun 10, 2005 12:04 pm Post subject: |
|
|
I'm bumping this, as I'd like to know something more: what is the reccomended way to set the PATH variable for ccache? The handbook says /etc/profile, yet people like numerodix say to modify /etc/env.d
So do I modily/create a file in /etc/env.d for ccache? Cause if I alter /etc/profile, I guess I'd have to alter both PATH and ROOTPATH right? _________________ There is no spoon...
Oh, and it's WINDOWS not Winblowz for those who can't spell |
|
Back to top |
|
 |
|