Some dumb questions born of frustration
karl at karlwilbur.net
Thu Oct 27 20:47:19 UTC 2016
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.
So, here's an answer from Stack Exchange the sums it up nicely:
.bash_profile is executed for login shells, while .bashrc is executed for
interactive non-login shells.
When you login[sic] (type username and password) via console, either
sitting at the machine, or remotely via ssh: .bash_profile is executed to
configure your shell before the initial command prompt.
But, if you’ve already logged into your machine and open a new terminal
window (xterm) then .bashrc is executed before the window command prompt.
.bashrc is also run when you start a new bash instance by typing /bin/bash in
[from Stack Exchange question:
An instance of a interactive session would be something like this:
[karl at local-desktop] $ ssh karl at remote.server.net
[karl at local-desktop] $ ssh ~/bin/do-something.sh
.../home/karl/.bashrc is not loaded when bash starts on remote.server.net,
but /home/karl/.bash_profile is loaded for the interactive session.
An instance of a non-interactive command (or session) would be something
[karl at local-desktop] $ ssh karl at remote.server.net "~/bin/do-something.sh"
.../home/karl/.bash_profile is not loaded before
/home/karl/bin/do-something.sh is run on remote.server.net, but
/home/karl/.bashrc is loaded.
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.
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.
Now, my ~/.bash_profile only loads my ~/.bashrc:
I have started using a ~/.bash_interactive include for directives that
should only be run for interactive sessions.
Please feel free to ask any more questions about this. I'm glad to help
explain what I can.
karl at karlwilbur.net
On Thu, Oct 27, 2016 at 7:56 AM, Jeffery Mewtamer <mewtamer at gmail.com>
> Okay, created a single line .bash_profile with the source ~/.bashrc
> line and it works. Then, since both files are, for me at least, single
> liners, I tried .bash_profile with just the export PS1='\$' and no
> .bashrc and got the same result. For such minimalist configs, is there
> any reason to prefer a separate .bashrc?
> And now that I don't have to manually type PS1=$ everytime I switch to
> a fresh terminal, is there any way I could add a short indicator of
> the active terminal before the $? Something along the lines of tty2$
> when I'm using tty2 and tty3$ when I'm using tty3.
> Jeffery Wright
> President Emeritus, Nu Nu Chapter, Phi Theta Kappa.
> Former Secretary, Student Government Association, College of the Albemarle.
> Blinux-list mailing list
> Blinux-list at redhat.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Blinux-list