Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug?] dotenv command $VARIABLE #23

Closed
jjangga0214 opened this issue Aug 8, 2019 · 1 comment
Closed

[bug?] dotenv command $VARIABLE #23

jjangga0214 opened this issue Aug 8, 2019 · 1 comment

Comments

@jjangga0214
Copy link

jjangga0214 commented Aug 8, 2019

Hi, thank you for this convenient cli :)

I found a strange behavior. dotenv does not work with direct use of an environment variable.

Let's say my .env file is like the below.

# content of .env
MESSAGE=helloworld

I expect the command below would print "helloworld" on the console.

$ dotenv echo $MESSAGE

However, it doesn't. If an environment variable is directly used on the command after dotenv, then the value is not properly populated.

So, assume I made a file greeting.sh like this.

# content of greeting.sh
echo $MESSAGE

And I changed the command like the below.

$ dotenv ./greeting.sh

And now it works!

This might be quite unexpected to users, isn't it?
I think it'd be better to allow direct use of environment variables after dotenv.
How do you feel?

Thanks.

@entropitor
Copy link
Owner

entropitor commented Aug 8, 2019

Hey! Thanks for the bug report. The problem is with the way the shell works. If you run

$ dotenv echo $MESSAGE

your shell will first interpolate the value $MESSAGE and then run the command with the value interpolated

$ dotenv echo ""

so dotenv-cli will get the arguments echo "" so it's impossible to know that $MESSAGE was passed.

What you could do: launch a bash shell with the command "echo $MESSAGE". For this to work, you need to escape the $ or use single quotes

$ dotenv -- bash -c "echo \$MESSAGE"
$ dotenv -- bash -c 'echo $MESSAGE'

I hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants