3

I would like to be able to create some files in a directory (e.g. *.env) and then have my ZSH / BASH automatically load the environment variables defined in them / unload when I change the directory.

It would be best if a file ~/project/local.env would define environment variables for all of its (nested) subfolders.

It should be gratis and work on Ubuntu 18.04.

4
  • Which software are you asking us to recommend? This sounds more like a question for unix.stackexchange.com Nov 9, 2018 at 10:52
  • If I knew the name of the software I want, why would I go to this site? Nov 9, 2018 at 11:04
  • Lol! Sorry (and I intended no offence), It's not about the name of some app. It's that, when I read your question (and maybe it is just me), you don't seem to be asking "what software app can do this for me". It reads more like "how can I do this from the command line, or with a .bashrc file, or similar?". If I were you, I would prefer to do it with existing Linux commands if possible, rather than add a new software. If you agree, delete this question and ask on our Linux site. If they can't help, then come back here (but don't cross-post). Whichever you chose, I wish you good luck :-) Nov 9, 2018 at 11:12
  • 1
    I'm 99% certain that I cannot do it with the software I have installed. It might be only a ZSH plugin, but I need something else. Nov 9, 2018 at 12:06

1 Answer 1

1

direnv is what I was looking for:

  • Install via sudo apt-get install direnv
  • In some target folder, create a .envrc file and add some export(1) directives in it.
  • the contents of the .envrc file must be valid bash syntax, regardless of the shell you are using
  • You have to enable it once per directory with direnv allow .
1
  • Thank you very much for sharing the answer with us. That will help others in future Nov 20, 2018 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.