LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   PATH From ~/.profile is only added when logging in remotely (https://www.linuxquestions.org/questions/linux-newbie-8/path-from-%7E-profile-is-only-added-when-logging-in-remotely-4175529942/)

linux_walt 01-03-2015 02:48 PM

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!

weibullguy 01-03-2015 02:52 PM

https://www.gnu.org/software/bash/ma...tup-Files.html

linux_walt 01-03-2015 03:15 PM

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.

btmiller 01-03-2015 03:34 PM

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.

linux_walt 01-03-2015 04:08 PM

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!

linux_walt 01-03-2015 05:27 PM

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?

btmiller 01-04-2015 09:41 AM

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.

linux_walt 01-04-2015 10:53 AM

Thanks! I'll mark the thread solved.


All times are GMT -5. The time now is 01:21 AM.