shdotenv seems to ignore -e /dev/null
theodiem opened this issue · 1 comments
Unless I understood the docs wrong, shdotenv export
ignores -e /dev/null
Ex:
$ echo "VAR1=foo" > .env
$ shdotenv -e /dev/null -e .env export
HOME='/root'
PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
PWD='/tmp'
SHLVL='2'
TERM='xterm'
VAR1='foo'
Expected behavior
$ echo "VAR1=foo" > .env
$ shdotenv -e /dev/null -e .env export
VAR1='foo'
Environment:
- OS: linux (alpine:3.17 container)
- awk version: GNU awk 5.1.1
Additional context
I would like to use shdotenv to manipulate an env file ensuring that file is valid and merging files, for example:
echo "VAR1=foo" > .existing.env
MYOUTPUT=$(echo 'value that I have no idea on how to escape')
shdotenv export MYOUTPUT | shdotenv -e /dev/null -e existing.env -e - export
Of course I can do shdotenv export MYOUTPUT >> existing.env
and rely that values would be overwritten due their order, but I would prefer to use shdotenv to keep the env file cleaner.
shdotenv merges all specified .env files.
$ cat .env
VAR=123
$ cat .env2
VAR2=456
$ env -i shdotenv -e .env -e .env2 export
PWD='/home/koichi/workspace/shdotenv'
VAR='123'
VAR2='456'
The general purpose of shdotenv is to load .env file and execute a command.
$ shdotenv any-command
If no command to execute is specified, the default output will be the environment variable setting code that can be evaluated by the POSIX shell.
$ env -i shdotenv -e .env -e .env2
export VAR='123'
export VAR2='456'
If the command specified is an export
command, it behaves similarly to the export command in the POSIX shell. In other words, all current environment variables are output.