Would not
sh -c '. .env; echo $MY_VAR'
do the same thing? (I am not in front of a shell at the moment.)
sh -c '. .env; echo $MY_VAR'
do the same thing? (I am not in front of a shell at the moment.)
I have this on my .bashrc:
alias loadenv='export $(xargs <.env)'
source: [1]--
loadenv() {
set -a
source ./.env
set +a
}... except I'm thinking this may `set +a` if the environment already had `set -a`, which maybe could cause problems? I wonder if it would make sense to record the existing status of "-a" (allexports) an set it / unset it as necessary.
loadenv() {
case "$-" in
*a*) source ./.env ;;
*) set -a; source ./.env; set +a ;;
esac
}
Although I have yet to see a long shellscript utilise `set -a` globally :) sh -ac '. ./.env; ./prog'
Also if you use the `.` builtin it's a good idea to specify the path with a slash in it, so that `.` doesn't search $PATH first.