<div dir="ltr">I wrote an entire article about this and posted it on my website about 10 years ago, but cannot find it now. :-( I went into great detail about the differences between /etc/profile, /etc/bashrc, ~/.profile, ~/.bash_profile, and ~/.bashrc. I also discussed when, how, and why they were used. I'll keep looking for it and reply here with a link if I find it.<div><br></div><div>So, here's an answer from Stack Exchange the sums it up nicely:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif"><code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">.bash_profile</code> is executed for login shells, while <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">.bashrc</code> is executed for interactive non-login shells.</p></div><div><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif">When you login[sic] (type username and password) via console, either sitting at the machine, or remotely via ssh: <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">.bash_profile</code> is executed to configure your shell before the initial command prompt.</p></div><div><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif">But, if you’ve already logged into your machine and open a new terminal window (xterm) then <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">.bashrc</code> is executed before the window command prompt. <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">.bashrc</code> is also run when you start a new bash instance by typing <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">/bin/bash</code> in a terminal.</p></div></blockquote><div><br></div><div>[from Stack Exchange question: <a href="http://apple.stackexchange.com/questions/51036/what-is-the-difference-between-bash-profile-and-bashrc">http://apple.stackexchange.com/questions/51036/what-is-the-difference-between-bash-profile-and-bashrc</a>]</div><div><br></div><div>An instance of a interactive session would be something like this:<br></div><div><div>[karl@local-desktop] $ ssh <a href="mailto:karl@remote.server.net">karl@remote.server.net</a> </div><div>[karl@local-desktop] $ ssh ~/bin/do-something.sh</div><div>.../home/karl/.bashrc is not loaded when bash starts on <a href="http://remote.server.net">remote.server.net</a>, but /home/karl/.bash_profile is loaded for the interactive session.</div></div><div><br></div><div>An instance of a non-interactive command (or session) would be something like this:</div><div>[karl@local-desktop] $ ssh <a href="mailto:karl@remote.server.net">karl@remote.server.net</a> "~/bin/do-something.sh"</div><div>.../home/karl/.bash_profile is not loaded before /home/karl/bin/do-something.sh is run on <a href="http://remote.server.net">remote.server.net</a>, but /home/karl/.bashrc is loaded.</div><div><br></div><div>Personally, I preferred to keep directives that are for *Bash* configuration (the way *I* expect Bash to *run*) in my ~/.bashrc. I would put formatting, and "profile" information into the .bash_profile; including things like how the command prompt should appear ($PS1). Since aesthetic and user interface directives are insignificant to shell script execution, I kept them separate. It helped me keep things a little more organized.</div><div><br></div><div>I have since given up and dumped it all in .bashrc because it seems that the vast majority of software maintainers don't understand the nuance and I felt like I was wasting a lot of time reworking every singe install script for the various tools I implement.</div><div><br></div><div>Now, my ~/.bash_profile only loads my ~/.bashrc:<br></div><div><a href="https://github.com/karlwilbur/castle/blob/master/home/.bash_profile">https://github.com/karlwilbur/castle/blob/master/home/.bash_profile</a><br></div><div><br></div><div>I have started using a ~/.bash_interactive include for directives that should only be run for interactive sessions.</div><div><a href="https://github.com/karlwilbur/castle/blob/master/home/.rc.d/bash_interactive">https://github.com/karlwilbur/castle/blob/master/home/.rc.d/bash_interactive</a><br></div><div><br></div><div>Please feel free to ask any more questions about this. I'm glad to help explain what I can.</div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">--<br>Karl Wilbur<br>513-322-2481<br><a href="mailto:karl@karlwilbur.net" target="_blank">karl@karlwilbur.net</a></div></div>
<br><div class="gmail_quote">On Thu, Oct 27, 2016 at 7:56 AM, Jeffery Mewtamer <span dir="ltr"><<a href="mailto:mewtamer@gmail.com" target="_blank">mewtamer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Okay, created a single line .bash_profile with the source ~/.bashrc<br>
line and it works. Then, since both files are, for me at least, single<br>
liners, I tried .bash_profile with just the export PS1='\$' and no<br>
.bashrc and got the same result. For such minimalist configs, is there<br>
any reason to prefer a separate .bashrc?<br>
<br>
And now that I don't have to manually type PS1=$ everytime I switch to<br>
a fresh terminal, is there any way I could add a short indicator of<br>
the active terminal before the $? Something along the lines of tty2$<br>
when I'm using tty2 and tty3$ when I'm using tty3.<br>
<div class="HOEnZb"><div class="h5"><br>
--<br>
Sincerely,<br>
<br>
Jeffery Wright<br>
President Emeritus, Nu Nu Chapter, Phi Theta Kappa.<br>
Former Secretary, Student Government Association, College of the Albemarle.<br>
<br>
______________________________<wbr>_________________<br>
Blinux-list mailing list<br>
<a href="mailto:Blinux-list@redhat.com">Blinux-list@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/blinux-list" rel="noreferrer" target="_blank">https://www.redhat.com/<wbr>mailman/listinfo/blinux-list</a><br>
</div></div></blockquote></div><br></div>