Inside of ~/.bashrc
, I run a bash script (a script with #!/usr/bin/env bash
at the top). I have found that when BASH_ENV
is set to my ~/.bashrc
that this sets up an infinite loop when a bash command is run. What is the best way to avoid this?
Here is my understanding of what happens (see also the bash manual on startup files):
bash
run non-interactively resolvesBASH_ENV
to~/.bashrc
.bash
begins sourcing~/.bashrc
.bash
gets to the line in~/.bashrc
that calls the bash script and starts abash
subprocess.- The
bash
subprocess resolvesBASH_ENV
to~/.bashrc
and so goes back to step 1 here, setting up an infinite loop.
I came across this issue because I wanted to run some cron jobs using my standard environment and found suggestions to set BASH_ENV
within the crontab. I am posting this as a question here because I couldn't find the issue discussed in my searches online and it seems like something could bite others. I am posting my own solution below, but there may be better ones.