~/.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):
bashrun non-interactively resolves
bashgets to the line in
~/.bashrcthat calls the bash script and starts a
~/.bashrcand 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.