usage question: cannot export .env variables using lets
Closed this issue · 2 comments
This is probably not an issue with lets-cli, just something I've looked up on stack overflow and cannot get it to work.
I want to export variables in a docker swarm project:
load-env:
description: Loads environment variables specified in stacks/swarm.env into the current shell.
cmd: set -a; . stacks/swarm.env; set +a
Running set -a; . stacks/swarm.env; set +a
exports the variables in the env file, but running lets load-env
does not. I haven't been able to figure out why.
I also tried export $(cat stacks/swarm.env) > /dev/null 2>&1;
and it works the same way.
lets load-env
works well as a dependency of other cmds, so this is a no issue for me.
Sorry for the late response.
It is not possible to export env variables to your current shell using lets, for example
echo $MYVAR # no variable in env
lets expose-env # where export MYVAR=1 happens
echo $MYVAR # still no variable
It is because lets starts new shell under the hood (basically sh -c
)
But it you want to export vars to use them in lets cms itself - that should work:
mycommand:
cmd: |
export VAR1=1
source .env # where export VAR2=2
echo $VAR1 # shows 1
echo $VAR2 # shows 2