nickstenning / honcho

Honcho: a python clone of Foreman. For managing Procfile-based applications.
http://pypi.python.org/pypi/honcho
MIT License
1.59k stars 145 forks source link

honcho run doesn't load .env variables #232

Closed scalp42 closed 2 years ago

scalp42 commented 2 years ago

Hey @nickstenning

Quick testing and running into an issue.

Assuming the following .env:

NAME=anthony

Result seems off:

$> honcho -e .env run echo $NAME

Where I would have expected:

$> honcho -e .env run echo $NAME
anthony

Let me know if I'm missing anything, thanks in advance! 🙌

nickstenning commented 2 years ago

Hey @scalp42. I think this is a misunderstanding of how and when your shell interpolates environment variables. When you run

honcho -e .env run echo $NAME

it's your shell (and not honcho) that interpolates the value of $NAME before running the command. If $NAME isn't set then it will evaluate to nothing and the command you run will actually be

honcho -e .env run echo

which, understandably, just prints a newline.

You should be able to confirm that honcho itself exposes environment variables loaded from .env files by running something like this instead:

honcho -e .env run sh -c 'echo $NAME'

I expect that will print what you are hoping for.

You can also verify that it's your shell that's doing the interpolation of an empty variable by rerunning your command after running set -u in your shell. You'll probably see something like this:

$ set -u
$ honcho run -e .env echo $NAME
bash: NAME: unbound variable
scalp42 commented 2 years ago

Oh wow I feel stupid for missing this 🙈

Thanks for the quick answer by the way and thank you for the project! 🙏