Live data from Hacker News

Show HN: Dotenv, if it is a Unix utility

github.com

1–10 of 108 posts

Show HN: Dotenv, if it is a Unix utility

#1
I like the idea of using dotenv files, but I dislike having to use different language-specific libraries to read them.

To solve this, I created a small utility that lets you prefix any command with "dotenv" to load the ".env" file.

This is how I imagine dotenv would work if it had started as a UNIX utility rather than a Node.js library.

Show HN: Dotenv, if it is a Unix utility
github.com

Re: Show HN: Dotenv, if it is a Unix utility

#7
post #2

I think direnv already does a good job in this space, and it's already available in your package manager. https://direnv.net/

I've used direnv, but I think a nice property of OP's dotenv is that it's explicit: if I want to pass env vars, I run my program under it. If I don't, then I don't. There's no "hidden behavior" for me to forget about and then get surprised by.

Re: Show HN: Dotenv, if it is a Unix utility

#10
post #6

Would not sh -c '. .env; echo $MY_VAR' do the same thing? (I am not in front of a shell at the moment.)

You'd need to `set -a` or pass the `-a` as a flag to have them auto-exported though, so:

    sh -ac '. ./.env; ./prog'
Also if you use the `.` builtin it's a good idea to specify the path with a slash in it, so that `.` doesn't search $PATH first.
Post reply on HN