test-env v1.0.1
SYNOPSIS
Bash has no ternary operator and if-statements do not read clearly inside a
package.json. This program helps test environment variables and create
conditional output.
EXAMPLE
package.json scripts likely want some context about their environment. In
this example we want to add the --debug flag to the browserify program
before we run it, but only if the NODE_ENV environment variable has not
been set.
"scripts": {
"build-js": "browserify $(test-env !NODE_ENV '--debug') browser/*.js > static/bundle.js"
}USAGE
TESTING
Truthy Variables. If the test is truthy, Yes will be written to stdout. If
the test is falsy, nothing will be output. If the test is false, and a third
variable is supplied it will be printed.
$test-env VARIABLE_NAME "Yes"
$test-env VARIABLE_NAME "Yes" "No"Falsy Variables. If the test is falsy, Yes will be written to stdout. If
the test is falsy, nothing will be output. If the test is false, and a third
variable is supplied it will be printed.
$test-env !USER "Yes"
$test-env !USER "Yes" "No"COMPARING
The comparison operators for equality are supported
==(oreq) Equal!=(ornot) Not EqualgtGreater ThanltLess ThangteGreater Than or Equal TolteLess Than or Equal To
More examples
$test-env USER "Yes"
Yes$test-env SHLVL == 2 Yep Nope
Yep$test-env SHLVL >= 1 Tak Niet
Tak