Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Evaluator for common shell variable expressions

Project description

Homepage:Shellvars Homepage
Download:Shellvars on PyPI
Documentation:Shellvars Docs
License:MIT License
Support:Mailing list (
Issue tracker:Github Issues
Build status:


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}

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.


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', {})


Use pip to install:

pip install shellvars


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.


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

Project details

Download files

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

Files for shellvars, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size shellvars-1.0.0-py2.py3-none-any.whl (11.5 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size shellvars-1.0.0.tar.gz (7.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page