I've read that .bashrc (like .zshrc) is meant only for interactive logins (and the one non-interactive exception of remote shells). But where should environment variables for Bash be placed that is (roughly) equivalent to .zshenv?

1 Answer 1


That would be the $BASH_ENV environment variable.

info bash BASH_ENV:

If this variable is set when Bash is invoked to execute a shell script, its value is expanded and used as the name of a startup file to read before executing the script. *Note Bash Startup Files::.

So you'd set that variable to ~/.bashenv for instance in your ~/.profile for all non-interactive bash instances though not the ones invoked as sh to interpret code in that file upon startup.

To do that for interactive ones as well, you can add a source ~/.bashenv to your ~/.bashrc (maybe also in your ~/.bash_profile if it doesn't already source your ~/.bashrc when interactive).

  • If you set $BASH_ENV in your ~/.profile, then isn't ~/.profile the one closest to /.zshenv for Bash?
    – iconoclast
    Mar 18, 2022 at 15:44
  • 1
    ~/.profile is like ~/.zprofile, it's the login session initialisation file. You can set env vars that will be inherited by commands started within that session there. Mar 18, 2022 at 15:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .