I'm using Zsh. Here is the ENV file:
and my .bash_profile:
, each with one echo command for debug. When I start a new shell process sh,
it runs as child shell, and there's no debug output. If I change to bash,
I get the same result, still no debug output.
Surely, if I login with bash
chsh -s /bin/bash
, the ~/.bash_profile would get sourced
and the ENV variable get set and exported as expected. However, Why doesn't the ENV file, namely ~/.bashenv, get sourced by bash or sh?
CodePudding user response:
I learned something could explain my issue when reading:
For Bash users, the ENV file is read only when Bash is invoked with the name sh, with the --posix command-line option, or after set –o posix is executed (all of which force POSIX standard compliance).
Since variable ENV has been exported to subshells, sh would try to source the ENV file, because this time I use the name sh:
So, here's the key point to fix this:
We should use the name
shto invokebash.ENVvariable should be set and accessible first.








