withenv

command module
v0.0.0-...-fd32182 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2020 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

withenv

withenv runs a command with environment variables merged from multiple sources.

Install

Download the zero-install binary to a directory on your PATH.

Usage

Usage: withenv [--clear] [--env=<file|@|->...] [COMMAND [-- ARGS...]]

Run a command with environment from files - https://github.com/schmich/withenv

Arguments:
  COMMAND         Command to run.
  ARGS            Arguments to pass to command.

Options:
  -v, --version   Show the version and exit
  -c, --clear     Do not inherit current environment.
  -e, --env       Merge environment variables:
                  Use -e <file> to merge NAME=value entries from a file.
                  Use -e- to merge NAME=value entries from stdin.
                  Use -e @ to merge current environment.

Environment Files

Environment files define one environment variable per line. Blank lines and lines starting with # (comments) are ignored. No shell execution, substitution, or interpolation is performed. See the notes section for details.

Example
# Comments are ignored.
# Blank lines are also ignored.
# Values are handled verbatim as literal strings.

# Simple environment variable.
HELLO=world

# Empty value.
EMPTY_VAR=

# Spaces are allowed.
WITH_SPACES=A value with spaces, very cool.

# These are still ultimately strings.
SOME_INT=123
SOME_BOOL=false
SOME_NULL=null

# No environment substitution occurs.
NOT_SUBSTITUTED=$USER %USER%

# Shell commands aren't run.
JUST_A_STRING=$(pwd)
ALSO_A_STRING=`/bin/ls -lh`

# Single and double quotes are not removed.
QUOTED="Quotes are not removed from values"
SINGLE='Single quotes are not removed either'
ESCAPED=This \"is\" (''also'') \\`verbatim`\\

# AWS credentials.
AWS_ACCESS_KEY_ID=4cc355k3yid
AWS_SECRET_KEY=s0m3s3cr37

Examples

The following examples assume the following:

Current environment:

SOURCE=current
SHELL=/bin/bash

Environment file .env1:

SOURCE=env1
COLOR=blue

Environment file .env2:

SOURCE=env2
VOLUME=max

Example: Show merged environment after loading an environment file (useful for debugging):

$ withenv -e .env1
SHELL=/bin/bash
SOURCE=env1
COLOR=blue

Example: Merge multiple environments from multiple files:

$ withenv -e .env1 -e .env2
SHELL=/bin/bash
SOURCE=env2
COLOR=blue
VOLUME=max

Example: Do not inherit current environment. Use environment exclusively from file:

$ withenv -c -e .env1
SOURCE=env1
COLOR=blue

Example: Use environment from stdin:

$ cat .env1 | withenv -e-
SHELL=/bin/bash
SOURCE=env1
COLOR=blue

Example: Use environment from file with current environment taking precedence:

$ withenv -c -e .env1 -e @
SHELL=/bin/bash
SOURCE=current
COLOR=blue

Example: Run command with empty environment:

$ withenv -c /bin/ls

Example: Run a complex command with a merged environment:

$ withenv --clear --env .env.shared --env .env.production php -c /etc/php -f MyScript.php > out.log

Notes

  • Environment variables are case-sensitive
  • Environment variables match the pattern [A-Za-z_][A-Za-z0-9_]*
  • The target process is started using syscall.Exec, see execve(2)

License

Copyright © 2020 Chris Schmich
MIT License. See LICENSE for details.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址