Bash not loading '.profile' in new session on Linux
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Puzzle3
--
Chapters
00:00 Bash Not Loading '.Profile' In New Session On Linux
00:29 Accepted Answer Score 24
01:03 Answer 2 Score 19
02:00 Thank you
--
Full question
https://superuser.com/questions/176404/b...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#bash #terminal #shell #bashrc #bashprofile
#avk47
ACCEPTED ANSWER
Score 24
When Bash starts as an interactive login shell, one of the files it may process is ~/.profile
.
When it starts as an interactive non-login shell it doesn't. It processes /etc/bash.bashrc
(if that file or a similar file is enabled in your version of Bash) and ~/.bashrc
.
You could add the following to your ~/.bashrc
(but be careful of loops or values being changed inadvertently):
. $HOME/.profile
ANSWER 2
Score 19
It kind of depends how you start your shell. As others have said, a login shell will load your profile (it will look for .bash_profile first, then will try .profile). If it finds one of these, it loads them. A non-login shell (either interactive or non-interactive) will source .bashrc.
I'd suggest putting everything into .bashrc. The .profile/.bashrc split was kind of arbitrary and made more sense in the old days of UNIX when tty wasn't just a device name and meant an actual TeleType. It was meant to start certain things (like checking mail) on the 'main' login to a server, and just normal setup stuff for other shells. In most Linuxes you will log in now, you're not really logging into a shell, as you're logging into some graphical interface (KDE, gnome, CDE 'shudder'). The "spawn login processes" is now taken care of by your session manager. It's much less relevant now.
My suggestion: Make your .profile consist of solely:
[ -f $HOME/.bashrc ] && . $HOME/.bashrc
as the first line of .bashrc, guard against weird stuff happening when running a bash script by jumping out early:
[[ $- != *i* ]] && return