19:16
I think I want to fix this first. That answer of mine and all of the comments are wrong. But the comments being wrong is no excuse for me not to fix what is wrong in the answer, and the most recent comment (pointing out that my answer is wrong) would be mostly correct if not for the claim about a previous comment being right.
The one problem I'm sure my answer has is that one of its sections claims that
.bashrc
is sourced by noninteractive shells as well as interactive shells, but actually it is only sometimes run by noninteractive shells.
I believe the only wrong section is "Where to Put Commands to Run in non-Interactive Shells." Unfortunately, I think it is not really wrong in quite the way anyone has said it is.
I had ignored okwap's comment because, if one corrects the wrong claim about
/etc/bash.profile
(there is no such file and bash
wouldn't use if it there were), it was saying something that I had already said, clearly and in detail, in the preceding "Where to Put Commands for Login Shells and Interactive non-Login Shells" section.
If it's invoked with
--login
it sources profile files which, in Ubuntu unless they are edited in an usual way, source the "rc" files, as described.
But I don't think that's the only circumstance where a noninteractive shell sources
.bashrc
. I think you can have a noninteractive non-login shell started via ssh
and that it will source .bashrc
if it is able to tell that it is on an SSH connection.
This is actually in gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html, which Nick Allen commented linking to.
@Zanna I'm not worried about the situation where
$BASH_ENV
expands to .bashrc
, just like I'm not all that worried about the situation where profile files don't source rc files. (They don't have to, but the default in Ubuntu is that they do, it's weird for them not to, there's no general expectation that anyone changes that, and I do specifically explain precisely why they do in the immediately preceding section of the post.)
@Zanna Well, I think an ideal test would not have even a systemwide profile file contain code that sources an "rc" file. That's the problem. To make sure I'm not making a mistake, I have to make sure that the only way
.bashrc
would be run is because bash
guesses that it is sending output over a network connection. 19:48
That might be helpful. I may be able to test by then, though. What I'm trying to figure out how is (a) if such testing is really necessary, (b) how best to test, and (c) how best to fix the post without making it really complicated. Nick Allen has a point about brevity. On the other hand, the official source linked in Nick Allen's comment contradicts the claims made in the comment (because of SSH connections).
I don't know for sure that the comment is wrong, because I haven't verified that the official documentation is correct.
But I do know that the "Where to Put Commands to Run in non-Interactive Shells" section of my answer is wrong or, to be unreasonably kind to myself, written in such a way as to be extremely frequently misunderstood.
If I brought it in line with Nick Allen's comment (except the part about the preceding comment being correct), that would be better than no change.
I am worried that my post looks righter than it is because of the errors in the preceding comments (I mean, prior to Nick Allen's helpful one). To put it another way, I never fixed the post, because the preceding comments were so clearly wrong. If I was fooled by that, I can only assume some readers will be fooled as well.
If people read only as far as user423688's comment, they may notice that it is false that
.profile
is sourced only in interactive login shells, assume (correctly) that the comment as a whole is wrong, but assume (incorrectly) that my post itself is right. « first day (47 days earlier) ← previous day next day → last day (2520 days later) »