Skip to content

Instantly share code, notes, and snippets.

@daliborgogic
Last active September 3, 2018 14:00
Show Gist options
  • Save daliborgogic/ae3e8a5cf6a50d7ab096d5ad3f901829 to your computer and use it in GitHub Desktop.
Save daliborgogic/ae3e8a5cf6a50d7ab096d5ad3f901829 to your computer and use it in GitHub Desktop.
Set environment variables from file
$ cat > .env << EOL
foo=foo
foobar="foo bar"
EOL

$ env grep -v '^#' .env | xargs -d '\n' -t
echo  foo=foo foobar="foo bar" 
env: ‘bar"’: No such file or directory

$ env $(grep -v '^#' .env | xargs -d '\n') node_modules/.bin/micro -l tcp://0.0.0.0:3000
env: ‘bar"’: No such file or directory
@daliborgogic
Copy link
Author

daliborgogic commented Sep 1, 2018

Expected output

foo=foo foobar="foo bar" node_modules/.bin/micro -l tcp://0.0.0.0:3000

@daliborgogic
Copy link
Author

daliborgogic commented Sep 3, 2018

Real example

$ cat > .env << EOL
FIRST_NAME=John
LAST_NAME=Doe
EOL
$ env $(grep -v '^#' .env | xargs -d '\n') node_modules/.bin/micro -l tcp://0.0.0.0:3000

Problem tmp solved

const { FIRST_NAME, LAST_NAME }  = process.env
const fullName = FIRST_NAME + '  ' + LAST_NAME

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment