LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-03-2015, 02:48 PM   #1
linux_walt
Member
 
Registered: Dec 2014
Location: Houston, TX
Distribution: Debian wheezy
Posts: 127

Rep: Reputation: 29
PATH From ~/.profile is only added when logging in remotely


Hello, in my ~/.profile I have this line:
Code:
PATH=$HOME/bin:$PATH
I do not have either ~/.bash_profile or ~/.bash_login.

When I log in remotely, using ssh, the PATH=$HOME/bin:$PATH is added:
Code:
:~$ echo $PATH
/home/walter/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
It is not added if I login locally:
Code:
~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
Any ideas on why? Thanks!
 
Old 01-03-2015, 02:52 PM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
https://www.gnu.org/software/bash/ma...tup-Files.html
 
1 members found this post helpful.
Old 01-03-2015, 03:15 PM   #3
linux_walt
Member
 
Registered: Dec 2014
Location: Houston, TX
Distribution: Debian wheezy
Posts: 127

Original Poster
Rep: Reputation: 29
Thanks weibullguy, but doesn't it say ~/.profile will be read, if you do not have ~/.bash_profile and ~/.bash_login?

Quote:
Invoked as an interactive login shell, or with --login

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. The --noprofile option may be used when the shell is started to inhibit this behavior.
 
Old 01-03-2015, 03:34 PM   #4
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,284

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
The thing is you need to understand the difference between a login and non-login shell. When you login remotely, you invoke a login shell, but a shell opened from a GUI is a non-login shell (since you're already logged in).

What I like to do is have .bash_profile source .bashrc. The .bashrc file is always read, regardless of whether the shell is a login shell or not.
 
1 members found this post helpful.
Old 01-03-2015, 04:08 PM   #5
linux_walt
Member
 
Registered: Dec 2014
Location: Houston, TX
Distribution: Debian wheezy
Posts: 127

Original Poster
Rep: Reputation: 29
Ok, thanks btmiller, I may be starting to understand, although it doesn't make a lot of sense at the moment.

If I login remotely, a login shell is used, so .profile is read. Ok up to here.

When I login locally, using the GUI login screen, is .profile read?

Once logged in, if I open a terminal window, that will be a non-login shell,
so .profile is not read. However, since I am already logged in, shouldn't my PATH variable already have been set from .profile? Also I may have previously logged in remotely, so .profile has already been read.

Does each instance of me logging in create a different user shell, where changes from other shells are not seen? If that makes sense.

If you could, what did you mean by 'have .bash_profile source .bashrc'?

Thanks!
 
Old 01-03-2015, 05:27 PM   #6
linux_walt
Member
 
Registered: Dec 2014
Location: Houston, TX
Distribution: Debian wheezy
Posts: 127

Original Poster
Rep: Reputation: 29
It seems fixed now.

I created a new .bash_profile, with 'source bashrc' code from the .profile file:
Code:
~$ cat .bash_profile
# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi
Then added this (also from the .profile file) to the bottom of .bashrc
Code:
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi
It works, but is it ok? Can .profile be deleted?

Also, less important now, but which of these files is read when first logging in from the GUI login screen?

Last edited by linux_walt; 01-03-2015 at 05:39 PM.
 
Old 01-04-2015, 09:41 AM   #7
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,284

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
I think you can safely delete .profile now (might want to make a back-up copy).

When you login to the GUI, what gets run is entirely dependent on what desktop and window manager you are using. X11 itself reads ~/.xinitrc or its global equivalent, which usually just contains commands to start the window manager or desktop environment. Since a GUI desktop is not a shell, there's not something really 100% equivalent to the profile file that gets sourced.
 
1 members found this post helpful.
Old 01-04-2015, 10:53 AM   #8
linux_walt
Member
 
Registered: Dec 2014
Location: Houston, TX
Distribution: Debian wheezy
Posts: 127

Original Poster
Rep: Reputation: 29
Thanks! I'll mark the thread solved.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Do you add to the path line or make a new path in /etc/profile? M$ISBS Linux - Newbie 2 12-13-2006 02:14 PM
Logging into the console remotely Josh100 Linux - Newbie 3 05-09-2006 06:40 AM
Set the path systemwide/Set the path for a user with Slackware jayhel Slackware 1 06-12-2005 12:24 AM
logging off remotely ceph Linux - Security 1 07-20-2004 12:31 AM
How to set PATH How do I set PATH environment variable? Tranquil Linux - Newbie 3 11-02-2003 02:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration