« first day (47 days earlier)      last day (2352 days later) » 

7:16 PM
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.
 
7:32 PM
So, a non-interactive shell will only execute whatever $BASH_ENV expands to
?
Which might be .bashrc? And might be unset? Or am I not getting this?
 
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.
I have no convenient way to test that right now -- both the machines I might use for testing or virtualization are in use for other purposes.
 
Oh right! Well I can definitely try to test it for you, if you ELI5 what to do, because I'm completely clueless about SSH
 
@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.
So one way to test it would be to create a Debian or Ubuntu system with debootstrap, chroot into it, run an ssh server, make sure that works, then move all the default systemwide and user configuration files for bash aside. I think that's actually harder and a bit more error-prone that using a VM.
 
I'm not at home now; I'm on mobile, on a train... but I can play around any way with my Ubuntus later (er, maybe in about 11 hours?)
 
7:48 PM
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.
Really that section of my answer is wrong. I said this, which is wrong:
> In bash, the "rc" files are actually run whether the shell is interactive or not.
I could make it correct by saying "sometimes" or "may be," but that wouldn't actually help people.
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.
If I brought it in line with previous comments, that would be worse 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.
I really should have found and fixed the wrong information in this post some time ago.
 
8:07 PM
Sorry, I wasn't expecting to have to pay attention to something outside this conversation, but I did
@EliahKagan so, are you planning to enumerate the situations when rc files are sourced by noninteractive shells, and explaining where to put commands for those shells for situations when they do not? I should actually read the question...
 
No apology necessary. I just walked back to my computer and saw your message. :)
@Zanna Not if I can help it, because the question is primarily about /etc/profile, and the answer is already correct about when that gets run. I just want the claims made about /etc/bash.bashrc and ~/.bashrc to be correct and not misleading.
 
Hmm :S
 
8:33 PM
It seems tricky to avoid doing that. Unless that section sort of changed purpose, from being how to do x to note about x.
Back in a little while
 
9:20 PM
Ok. If I manage to edit the post, I'll try to mention it here.
 
Sorry not to be any help with it :/ You missed a p in "stopped" in the last section I think, btw
 

« first day (47 days earlier)      last day (2352 days later) »