News for hackers. Stuff that matters.
Re:Stupid Unix Tricks by robohoe on Thursday October 17, 2019 @09:01AM (#21281529)
.bashrc would get executed when you run something in cron. Cron runs non-interactive shell sessions.
Re:Stupid Unix Tricks by roryrjb on Thursday October 17, 2019 @09:11AM (#21281627)
I tested this and this is not the case. My .bashrc does a lot of things such as custom completions that are expensive that I would not want run by anything else other than an interactive shell. It also has return at the end so if anything I don't know about adds stuff to it, it won't get executed. This would break other scripts loading .bashrc as well. So as far as I can see this is false.
Re:Stupid Unix Tricks by tremon on Thursday October 17, 2019 @09:29AM (#21281795)
From the manual:

When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by using the --norc option.

So interactive, non-login shells only.

But also:

When invoked as an interactive shell with the name sh , bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute. [A] shell invoked as sh does not attempt to read and execute commands from any other startup files

So only when invoked as bash, not as sh.

Re:Stupid Unix Tricks by roryrjb on Thursday October 17, 2019 @09:31AM (#21281823)
Thank you, very helpful. That explains why I have to have my .bash_profile source .bashrc for use with tmux, as it executes bash as a login shell. I knew I had to have this but wasn't 100% on why until now. Note to self, RTFM!