Help with PATH

The place to post if you need help or advice

Moderators: ChrisThornett, LXF moderators

Help with PATH

Postby DavePritchard » Fri Jan 10, 2014 11:05 pm

I am trying to get the XDS Module-2 Compiler working,
the xds directory has been installed in /usr/local,
The instructions then state :-
After installation, edit your path environment variable to append path to the "/usr/local/xds/bin" directory.

I have found information that states that PATH should be modified in the .bash_profile, but other information states in /etc/profile.

So three questions :-
1) Which file should I alter.
2) How do I alter it, Syntax.
3) Which line should be changed.

The code of the two files is as follows :-

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

# .bash_profile

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

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME

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


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

loginsh=1

if [ "$UID" -ge 500 ] && ! echo ${PATH} |grep -q /usr/games ; then
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 [ -r $i ]; then
. $i
fi
done

unset i
DavePritchard
 
Posts: 48
Joined: Tue Jan 09, 2007 10:55 pm
Location: Somerset UK

Postby MartyBartfast » Fri Jan 10, 2014 11:39 pm

I would change .bash_profile

change
Code: Select all
PATH=$PATH:$HOME/bin


to
Code: Select all
PATH=$PATH:$HOME/bin:/usr/local/xds/bin
I have been touched by his noodly appendage.
User avatar
MartyBartfast
LXF regular
 
Posts: 815
Joined: Mon Aug 22, 2005 7:25 am
Location: Hants, UK

Postby roseway » Sat Jan 11, 2014 7:40 am

I think ~/.profile is the proper place to add a path. As its name suggests, ~/.bash_profile applies to the bash shell (and will be run every time the user opens a bash shell), whereas .profile applies to everything the user does (and is run only once at login time).
Eric
roseway
LXF regular
 
Posts: 448
Joined: Thu Jan 18, 2007 2:27 pm

Postby nelz » Sat Jan 11, 2014 10:20 am

It depends on whether you want to set the path just for you or for all users. In the latter case, /etc/profile or /etc/profile.d/ is the best place, if it is just for you, ~/.profile.

The line to add, in either case, is

Code: Select all
PATH="$PATH:/usr/local/xds/bin"
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8499
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Help with PATH

Postby DavePritchard » Sat Jan 11, 2014 11:16 am

Thanks for the replies guys,
I thought I would go with ~/.profile
But I cannot find the file using 'find'.

Searching with find, including any of the ~ / or . has no result.
Searching with find, using just "profile", results in the following :-
file:///etc/profile
file:///usr/include/c++/4.5.2/profile
file:///usr/lib/firefox-6.0.2/defaults/profile
file:///usr/lib/kompozer/defaults/profile

Single user, & PC-Linux
DavePritchard
 
Posts: 48
Joined: Tue Jan 09, 2007 10:55 pm
Location: Somerset UK

Postby nelz » Sat Jan 11, 2014 2:07 pm

According to the bash man page
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.


So .profile wouldn't be used unless it was sourced from .bash_profile. Stick with .bash_profile. Life was much simpler when we had just /etc/profile and ~/.profile, until Bash complicated it all with umpteen extra files.
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8499
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby roseway » Sat Jan 11, 2014 6:52 pm

So .profile wouldn't be used unless it was sourced from .bash_profile. Stick with .bash_profile. Life was much simpler when we had just /etc/profile and ~/.profile, until Bash complicated it all with umpteen extra files.


I don't think that's correct. ~/.profile is used when you first log in.
Eric
roseway
LXF regular
 
Posts: 448
Joined: Thu Jan 18, 2007 2:27 pm

Postby nelz » Sat Jan 11, 2014 9:41 pm

Neither Bash nor Zsh sources ~/.profile is one of the more shell-specific profile files exists, as per the quote from the Bash man page and verified by experimentation. Some distros work around this by sourcing ~/.profile from ~/.bash_profile, but Bash does not source it directly.
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8499
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby roseway » Sat Jan 11, 2014 11:04 pm

Sorry to be argumentative, but Bash doesn't need to run ~/.profile itself. If you set up the path correctly in ~/.profile, the result will apply to everything the user does. 'Correctly' in this context means using export with the PATH line:

export PATH=$PATH:$HOME/bin:/usr/local/xds/bin
Eric
roseway
LXF regular
 
Posts: 448
Joined: Thu Jan 18, 2007 2:27 pm

Postby nelz » Sun Jan 12, 2014 11:53 am

That depends on your desktop. It certainly doesn't apply with KDE. Something has to source ~/.profile and if bash doesn't you are relying on something else to do it. Even if your desktop does, you still wouldn't have the variable set in a console session.

If you want it set, set it where you know it will be read by the software you want to use it (bash if that is your shell) rather than relying on the indeterminate behaviour f your desktop.

Code: Select all
cat ~/.profile
TEST="thisisatest"


After logging out of and back into the desktop

Code: Select all
echo x${TEST}x
xx
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8499
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby roseway » Sun Jan 12, 2014 12:57 pm

That depends on your desktop. It certainly doesn't apply with KDE. Something has to source ~/.profile and if bash doesn't you are relying on something else to do it. Even if your desktop does, you still wouldn't have the variable set in a console session.


It works perfectly well here. I use KDE. I opened Konsole and checked the value of PATH:

Code: Select all
eric@chaffinch:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
eric@chaffinch:~$


Then I added the following line to the end of ~/.profile:

Code: Select all
export PATH=$PATH:/usr/sbin


I then logged out and logged in again, opened Konsole and checked the value of PATH again:

Code: Select all
eric@chaffinch:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/sbin
eric@chaffinch:~$


So modifying the value of PATH in ~/.profile does get reflected in programs running in that environment.
Eric
roseway
LXF regular
 
Posts: 448
Joined: Thu Jan 18, 2007 2:27 pm

Postby nelz » Sun Jan 12, 2014 2:04 pm

So it works for 50% of the people that have tried it, which doesn't mean it should be recommended.

What does this give on your system?

Code: Select all
grep profile ~/.bash*
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8499
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby MartyBartfast » Sun Jan 12, 2014 3:38 pm

FWIW both .bash_profile, and .profile (which I didn't have until creating it for the purpose of this test) are executed after logging out/in to the desktop on my FC19, XFCE system:-

Code: Select all
martyn:~$ grep ZTEST .*profile
.bash_profile:export ZTEST2="set in .bash_profile"
.profile:export ZTEST1="set by .profile"
martyn:~$ grep "\.profile" .bash_profile
martyn:~$ set | grep ZTEST
ZTEST1='set by .profile'
ZTEST2='set in .bash_profile'
I have been touched by his noodly appendage.
User avatar
MartyBartfast
LXF regular
 
Posts: 815
Joined: Mon Aug 22, 2005 7:25 am
Location: Hants, UK

Postby nelz » Sun Jan 12, 2014 5:08 pm

Are they executed directly by the desktop or is one called from the other?
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8499
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby MartyBartfast » Sun Jan 12, 2014 6:06 pm

No they don't call each other and none of the usual profile/bashrc/login files calls .profile, either my own or in /etc; however I suspect it's this that's executing it:


Code: Select all
martyn:~$ grep "\.profile" /etc/X11/xinit/xinitrc-common
[ -r $HOME/.profile ] && . $HOME/.profile
I have been touched by his noodly appendage.
User avatar
MartyBartfast
LXF regular
 
Posts: 815
Joined: Mon Aug 22, 2005 7:25 am
Location: Hants, UK

Next

Return to Help!

Who is online

Users browsing this forum: guy and 2 guests