Skip to main content

A library for expanding shell ASTs

Project description

sh-expand

A python library for expanding shell ASTs that can be used to construct sound analyses for shell scripts (after having expanded the AST).

Design

There are two implementations of shell expansion:

  1. expand.py does an in-python expansion of simple & safe AST nodes. It doesn't support bashisms.
  2. bash_expand.py expands by conservatively echoing safe commands to a bash process containing the current shell state.

Both, when called via expand_command, recurse down into the words of a shasta AST node to expand, leave the word as is, or raise an ExpansionError. Examples:

  • Process substitutions are unsafe.
  • Simple variable substitutions are safe.
  • Assignments are considered unsafe, since in Pash they indicate an unparallelizable region.

expand.py interprets the ArgChars libdash parses (ex: for variable and process substitutions) to check and expand words.

Libbash does not parse ArgChars, so bash_expand.py instead conservatively checks for the presence of potentially expandable or unsafe literal characters (see should_expand_var) before expanding.

Not having proper ArgChar parsing causes false positive unsafe errors, so expand.py should eventually be extended to support bash-only AST nodes, and libbash and shasta extended to parse ArgChars.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sh_expand-0.2.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file sh_expand-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: sh_expand-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for sh_expand-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 64e8385eaa856f312fa8ffb876a001503618dd937ee756f02a589dc9d7042ad1
MD5 d55cfdca15dc33f128ada21801ebfdfb
BLAKE2b-256 8feb1f497a8042799a907413cb5c3ee6d32ec4b7874e8c6a5b92abd08ef4b512

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