WSL Bash environment

This article might clear up the confusion about the environment Bash shell runs in under Windows.

When you start the bash shell using the bash command, files such as ~/.bashrc, ~/.profile, etc. are loaded. This is expected behavior.

Now the counter-intuitive part. When you run a bash script using the bash command from Powershell, the script runs as a non-interactive bash script, which means, that the configuration files are not loaded.

If you directly access or any of the programs in the script depend on environment variables, it is best to source ~/.profile; source ~/.bashrc at the beginning of your script.

To complete this explanation, we should note, that opening the interactive shell and then running the bash script as non-interactive would work, but is usually impractical.