Skip to main content
Homepage:

Shellvars Homepage

Download:

Shellvars on PyPI

Documentation:

Shellvars Docs

License:

MIT License

Support:

Mailing list (testing-in-python@lists.idyll.org)

Issue tracker:

Github Issues

Build status:
https://travis-ci.org/testing-cabal/shellvars.svg?branch=master

Shellvars

A Python interpreter for shell variable expressions.

shellvars supports Python 2.6 and up, and should support Jython etc as well.

The following expressions are supported:

  • $NAME

  • ${NAME}

  • ${NAME:-REPLACEMENT}

  • ${NAME-REPLACEMENT}

  • ${NAME:=REPLACEMENT}

  • ${NAME=REPLACEMENT}

  • ${NAME:?[ERRORMSG]}

  • ${NAME?[ERRORMSG]}

  • ${NAME:+REPLACEMENT}

  • ${NAME+REPLACEMENT}

Recursive expressions are supported too. For instance:

>>> from shellvars import evaluate
>>> evaluate('${foo:-${bar:=baz}}', {})
('baz', {'bar': 'baz'})

For details on shell variable syntax, consult your shell or Posix documentation.

Usage

To evaluate an expression call evaluate with the expression and any variables you want available to the expression. Variables keys and values must both be strings. Variables that are missing from your variable dict are considered ‘unset’ in shell terms.

The return is an evaluated string and any variable assignments performed by the expression.

Preserving unset expressions

shellvars has a special mode where expressions that are for unset variables are preserved rather than evaluated. This permits passing them onto a real shell to interpret without needing special quoting from the user. For instance:

>>> from shellvars import SKIP
>>> evaluate('$foo $bar', {'foo': 'baz'}, absent=SKIP)
('baz $bar', {})

Installation

Use pip to install:

pip install shellvars

Development

Install the test dependencies via pip:

pip install .[test]

Push up changes as PR’s to the GitHub repository.

Bug tracker

Use the GitHub issue tracker.

Releasing

Use semver for version decisions.

To release:

  1. Tag the repo e.g. 1.2.3

  2. Build a signed sdist and wheel

  3. Upload to PyPI

Release files for shellvars 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shellvars 1.0.0
File Size Uploaded
shellvars-1.0.0.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shellvars 1.0.0
File Interpreter ABI Platform
shellvars-1.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size:19.0 kB

Release files / shellvars-1.0.0.tar.gz

Download URL shellvars-1.0.0.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
293b2306f0be24a17865ffdd86eed5a86b2b915ea7609acf5bef504bfa58469d
BLAKE2b-256 checksum
How to use checksums
5e98d9c87a43868b8a596c31ddb6d35d30b1d6e644eba1b0d85f88c042c86a82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / shellvars-1.0.0-py2.py3-none-any.whl

Download URL shellvars-1.0.0-py2.py3-none-any.whl
Size 11.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
fe4fd0235b48f4ab7f4aece905974510aa9aab81bb85dc3e89cc7566055a4e26
BLAKE2b-256 checksum
How to use checksums
fca6610f4d0f5ceaaaee2ea9974554bae8299ff8620c709bee7b8dea707cac76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page