dssg/envfile

Name: envfile

Owner: Data Science for Social Good

Description: POSIX-compatible script like env to run a program in an environment modified by values set in a file

Created: 2017-12-07 01:08:42.0

Updated: 2017-12-07 01:38:36.0

Pushed: 2017-12-07 02:08:04.0

Homepage: null

Size: 2

Language: Shell

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

envfile

POSIX-compatible script, like env, to run a program in an environment modified by values set in a file at the specified path.

This achieves the same as:

env NAME1=VALUE1 NAME2=VALUE2 make -d info

or, in shells which support it, omitting env:

NAME1=VALUE1 NAME2=VALUE2 make -d info

with the distinction that these values may be persisted to a file:

# dev.env

# The first setting
NAME1=VALUE1

# Oh and this is the second one
NAME2=VALUE2

and loaded into the execution environment:

envfile dev.env make -d info

like in the previous, on-the-fly examples, without polluting the user's shell environment.

Alternatives

It should be noted that something similar may be achieved with the source operator in a subshell:

(. dev.env && echo $NAME1)

which does not pollute the invoking environment.

However, the above only works for inline variable references, such as echo $NAME1. Any subprocess, such as make -d info, will not have access to the environment values declared by the environment file, unless this file uses export:

# dev.env

# The first setting
export NAME1=VALUE1

# Oh and this is the second one
export NAME2=VALUE2

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.