Skip to main content

Run a command with the subset of the current environment. env swiss army knife

Project description

env-subset -- Run a command with a subset of the environment

@readwithai - X - blog - machine-aided reading - 📖⚡️🖋️

Motivation

Programs change their behaviour based on the environment. It is therefore natural to want to be able to control the environment to control the program for debug and standard use. There are some tools for this - namely env and printenv but they are a little cumbersome.

This program is effectively "env with a lot of flags" to give you more control over the environment. This program is also more consistent than env and provides documentation via --help making it easier to install.

It is also released as open source code and can be installed with one (or two) lines on most systems.

Alternatives and prior work

You can hack up something quite similar to this use env, printenv, grep, bash -c etc. But this requires quite a lot of typing and is error prone.

If you want to change a single environment variable you can use e.g. env VAR=value printenv, bash and zsh can do this with VAR=value printenv. If you want to run without an environemt env -i printenv. If you want to run with a fixed environment you can use env -i env VAR=Value printenv. If you want to read environment variables from a file you can use env -i bash -c "source $file; printenv"

This is vaguely related to the idea of dotenv and python-dotenv.

Installation

You can install env-subset using pipx:

pipx install env-subset

Usage

Run ls is just the LANGUAGE environment. You can also use --variable

env-subset -e LANGUAGE ls

Run ls with both LANG and LANGUAGE

env-subset -e LANGUAGE ls

Run xterm with all the environment variables starting with X. This uses a regular expression. You can also use -r or --regexp

env-subset -e '/^X/' xterm

Run ls without the LANGUAGE enviornment variable - but with everything else. You can also use --exclude

env-subset -x -e LANGUAGE ls

Run a command with flags.

env-subset -e LANGUAGE -- python -m pdb

Set language to German:

env-subset -e LANGUAGE=de -e LANG=de -- python -m pdb

Read settings from a file. This can be generated with printenv but has some additional features. You can write the variable name along to take the variable from the outer scope. Write regular expressions of the form ^ to write a regular expression or // for a regular expression.

env-subset -f environment.env printenv

About me

I am @readwithai. I create tools for reading, research and agency sometimes using the markdown editor Obsidian.

I also create a stream of tools that are related to carrying out my work.

I write about lots of things - including tools like this - on X. My blog is more about reading and research and agency.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

env-subset-1.0.0.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file env-subset-1.0.0.tar.gz.

File metadata

  • Download URL: env-subset-1.0.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for env-subset-1.0.0.tar.gz
Algorithm Hash digest
SHA256 85aeeb17ab4b2ac0900385bc2a277a655a61edafd5cf6d3b5499e47c809cec89
MD5 4b1dc4f2bf4307da06004c52ebc15e1d
BLAKE2b-256 4e2bb7d74dad00035c9dd518c61d8e267125d911947f895690a31ce8054c8b54

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page