Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with PATH
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help!
View previous topic :: View next topic  
Author Message
DavePritchard



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

PostPosted: Fri Jan 10, 2014 11:05 pm    Post subject: Help with PATH Reply with quote

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
Back to top
View user's profile Send private message
MartyBartfast
LXF regular


Joined: Mon Aug 22, 2005 8:25 am
Posts: 814
Location: Hants, UK

PostPosted: Fri Jan 10, 2014 11:39 pm    Post subject: Reply with quote

I would change .bash_profile

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


to
Code:
PATH=$PATH:$HOME/bin:/usr/local/xds/bin

_________________
I have been touched by his noodly appendage.
Back to top
View user's profile Send private message
roseway
LXF regular


Joined: Thu Jan 18, 2007 2:27 pm
Posts: 446

PostPosted: Sat Jan 11, 2014 7:40 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8464
Location: Warrington, UK

PostPosted: Sat Jan 11, 2014 10:20 am    Post subject: Reply with quote

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:
PATH="$PATH:/usr/local/xds/bin"

_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
DavePritchard



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

PostPosted: Sat Jan 11, 2014 11:16 am    Post subject: Help with PATH Reply with quote

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
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8464
Location: Warrington, UK

PostPosted: Sat Jan 11, 2014 2:07 pm    Post subject: Reply with quote

According to the bash man page
Quote:
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)
Back to top
View user's profile Send private message
roseway
LXF regular


Joined: Thu Jan 18, 2007 2:27 pm
Posts: 446

PostPosted: Sat Jan 11, 2014 6:52 pm    Post subject: Reply with quote

Quote:
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
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8464
Location: Warrington, UK

PostPosted: Sat Jan 11, 2014 9:41 pm    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message
roseway
LXF regular


Joined: Thu Jan 18, 2007 2:27 pm
Posts: 446

PostPosted: Sat Jan 11, 2014 11:04 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8464
Location: Warrington, UK

PostPosted: Sun Jan 12, 2014 11:53 am    Post subject: Reply with quote

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:
cat ~/.profile
TEST="thisisatest"


After logging out of and back into the desktop

Code:
echo x${TEST}x
xx

_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
roseway
LXF regular


Joined: Thu Jan 18, 2007 2:27 pm
Posts: 446

PostPosted: Sun Jan 12, 2014 12:57 pm    Post subject: Reply with quote

Quote:
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:
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:
export PATH=$PATH:/usr/sbin


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

Code:
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
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8464
Location: Warrington, UK

PostPosted: Sun Jan 12, 2014 2:04 pm    Post subject: Reply with quote

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:
grep profile ~/.bash*

_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
MartyBartfast
LXF regular


Joined: Mon Aug 22, 2005 8:25 am
Posts: 814
Location: Hants, UK

PostPosted: Sun Jan 12, 2014 3:38 pm    Post subject: Reply with quote

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:

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.
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8464
Location: Warrington, UK

PostPosted: Sun Jan 12, 2014 5:08 pm    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message
MartyBartfast
LXF regular


Joined: Mon Aug 22, 2005 8:25 am
Posts: 814
Location: Hants, UK

PostPosted: Sun Jan 12, 2014 6:06 pm    Post subject: Reply with quote

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:

martyn:~$ grep "\.profile" /etc/X11/xinit/xinitrc-common
[ -r $HOME/.profile ] && . $HOME/.profile

_________________
I have been touched by his noodly appendage.
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help! All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast