Open aphilas opened 2 weeks ago
I think the help message is indeed a little unfortunate. After browsing the code, it seems the --export
or -e
is used only during the set operation. It prefixes the variable with the export
keyword.
To make you example work try providing --format shell
or --format export
to the list command.
For example eval $(dotenv -f ./.env list --format shell)
Check out this short bash session to figure out what happens when:
# -e adds "export" during "set" operation
dotenv -e 1 set ML "1
2
3"
cat .env
bash -c 'source .env' # bash can handle the format
# simple list
dotenv list
# can be handled by shell
dotenv list --format shell
# can be handled by shell, exports variables
dotenv list --format export
# eval and echo
eval $(dotenv list --format shell)
echo ML: $ML
# eval and echo with changed IFS to see the newlines
OLDIFS=$IFS
IFS=:
eval $(dotenv list --format shell)
echo ML: $ML
IFS=$OLDIFS
The description for
--export
says "Whether to write the dot file as executable bash script."However, if I used the
--export
flag with a multiline variable, the output cannot be correctly parsed by bash.For example:
Is this expected?
Alternatives workarounds I am aware of: