[HN Gopher] Show HN: Dotenv, if it is a Unix utility
       ___________________________________________________________________
        
       Show HN: Dotenv, if it is a Unix utility
        
       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.
        
       Author : gyf304
       Score  : 38 points
       Date   : 2024-04-28 20:25 UTC (2 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | petepete wrote:
       | I think direnv already does a good job in this space, and it's
       | already available in your package manager.
       | 
       | https://direnv.net/
        
         | kelnos wrote:
         | 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.
        
           | TheRoque wrote:
           | As far as I'm aware of, Direnv's behavior is not hidden at
           | all. Whenever you cd into the directory, you get a message
           | listing all the new en var activated. And when you change the
           | .envrc, you get another message saying that direnv has been
           | deactivated. I never had happen to me "oh shoot !! I forgot
           | this env var was activated because I'm in this dir".
        
       | tester457 wrote:
       | dotenv started as a ruby library actually. The first
       | implementation inspired the others such as the golang version of
       | the library.
        
       | miohtama wrote:
       | There is also shdotenv that allows you to load different .env
       | file formats and convert between them, e.g. for UNIX shell.
       | 
       | https://github.com/ko1nksm/shdotenv
        
       | mongol wrote:
       | Would not
       | 
       | sh -c '. .env; echo $MY_VAR'
       | 
       | do the same thing? (I am not in front of a shell at the moment.)
        
         | mixmastamyk wrote:
         | Seems to work.
        
         | kelnos wrote:
         | That would, but unless each line in your .env file is prefixed
         | with "export", those env vars won't get passed into any
         | subprocesses you run.
        
         | iokanuon wrote:
         | 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.
        
       | grounder wrote:
       | Compare with dotenvx - https://github.com/dotenvx/dotenvx This is
       | my current tool of choice.
        
       ___________________________________________________________________
       (page generated 2024-04-28 23:00 UTC)