3:54 AM
Then the shell metacharacter
(
appears in a subsequent word of the same command, in a context where the shell cannot give it any meaning. But it is unquoted. So that's a syntax error.
To avoid that problem, it doesn't actually matter where in the file one advises readers to put the alias definitions, so long as it's clear that they need to go on lines of their own.
As a secondary problem, which I don't expect to usually cause any trouble for alias definitions... it's generally bad to put code in
.bashrc
before this check except when one deliberately intends that it run in some non-interactive shells:
(This advice is largely specific to Debian and its derivatives, including Ubuntu, since other systems rarely have that check. They also often compile
bash
with a different configuration that is less likely ever to identify anything as the initial shell of a non-interactive remote session.)
Incidentally, this is one of the main reasons I had so much trouble figuring out, and actually never did end up figuring out, how to improve that old post while having it still make sense and without having it convey wrong information (either directly or by being confusing and leading to wrong assumptions).
But I did end up answering a question where a user suffered the practical effects of this misconception. I think this should make it easier to improve the old post.
4:38 AM
@EliahKagan But I still don't know how to make the change well. The default behavior in Debian and Ubuntu for which
bash
shells source .bashrc
on startup and which don't is that
(b) login shells source
.bashrc
indirectly whether or not they are interactive because both interactive and non-interactive login shells directly source .profile
, the default contents of which source .bashrc
when the running shell is bash
, and the code for that is not guarded by an interactivity check
(c) non-interactive non-login shells source
.bashrc
when bash
heuristically detects that it appears to be the inital shell in a remote session, which on some OSes literally never happens, but which on Ubuntu and Debian happens quite often, such as in ssh remote-host some-command
.
In the post I bascially say that
.bashrc
is always sourced, which is better than the usual claim that it is only sourced in interactive non-login shells (a claim that confuses the mechanism with the result and also is wrong about the mechanism). But it's still pretty bad. Like, running a script with bash -c some-commands
or bash /path/to/script
doesn't run .bashrc
...except sometimes when run via ssh
.
11 hours later…
3:52 PM
4:06 PM
4:30 PM
« first day (740 days earlier) ← previous day next day → last day (1710 days later) »