At the top of my .bashrc, it contains this command:
# If not running interactively, don't do anything case $- in *i*) ;; *) return;; esac
I never added this to my .bash.rc, because my .bashrc template was created by Ubuntu.
From what I have read, this command is to prevent the sourcing of the .bashrc file on a remote shell (rsh) or secure shell (ssh). If I were to have something like:
alias rm='rename' in my .bashrc, the alias above wouldn't work in the remote shell. However, if I didn't have that command, the alias would work. If "rename" was not installed on the remote shell, running
rm would throw an error. So the ultimate purpose is preventing unexpected behaviour, by blocking the sourcing of the .bashrc file.
So here is where I am confused. I completely removed this command and see no difference on a remote shell. I sourced my .bashrc before testing and even rebooted my system, but I see no unexpected behaviour (my 2 servers in this case) with ssh.
I tried simple tests like making an echo function in my .bashrc and trying to call it on the server. All I get is command not found: foo.
The only conclusion that I can come to is that because one of my servers has its own .bashrc and the other has a .zshrc, they take precedence over my local .bashrc, so it's never sourced. If that is the case, why do I need the above command at all? Is the above command archaic and no longer serving a purpose in 2022? Or maybe it does serve a purpose, but only for sysadmins who ssh into servers that don't have a .bashrc, .zshrc, or similar file.
TLDR: Do I need this in my .bashrc file If I only ssh into my own servers that have their own .bashrc or .zshrc file already?
.bashrcand the other has a
.zshrc, they take precedence over my local
.bashrc, so it's never sourced" – There is no room for precedence. The local file matters for the local shell, the remote file may matter for respective shell on the remote side. A remote shell has no means to read your local
.bashrc. When you say "at the top of my
.bashrc" or "removed this command [from
.bashrc]", or "do I need this in my
.bashrc?", do you mean your local
.bashrc? The code in question in the local file matters when you
sshto your local computer.