Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

foreman can read .env files and set environment variables from the contents, and then run a program

e.g. foreman run -e vars.env myprogram

...but it does a lot of other things (and is primarily concerned with starting things using its Procfile format).

Is there a simpler (Linux/Unix) tool that's just focussed on reading .env files and executing a command with the new environment?

Example environment file (from http://ddollar.github.io/foreman/#ENVIRONMENT ):

FOO=bar
BAZ=qux
share|improve this question
    
Can you post an example .env file? I suspect bash .env or sh .env may work? –  lVlint67 Sep 20 '13 at 1:28
    
@IVlint67 I've improved the question a little. –  wodow Sep 20 '13 at 13:26

3 Answers 3

up vote 3 down vote accepted

You can source the environment file in the active shell and run the program:

sh -ac ' . ./.env; /usr/local/bin/someprogram'

The -a switch exports all variables, so that they are available to the program.

share|improve this answer

This works:

env $(cat .env | tr "\\n" " ") myprogram

but obviously doesn't check the format of the .env file for correctness, which a utility program would do.

share|improve this answer
    
1) The cat is not necessary, just write tr "\\n" " " < .env 2) This breaks if multi-line assignments are used. –  Marco Sep 20 '13 at 13:44

Another alternative is envdir:

envdir runs another program with environment modified according to files in a specified directory.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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