Skip to main content

Bindings for the dash shell as a library

Project description

Main workflow

libdash is a fork of the Linux Kernel's dash shell that builds a linkable library with extra exposed interfaces. The primary use of libdash is to parse shell scripts, but it could be used for more.

The Python bindings are packaged as the libdash PyPi package.

The OCaml bindings---packaged as the libdash OPAM package---include two executables, shell_to_json and json_to_shell, which let you conveniently parse POSIX shell scripts into a JSON AST.

What are the dependencies?

The C code for dash should build on a wide variety of systems; it requires libtool and autotools (aclocal, autoheader, automake, autoconf). The library may not build on platforms with esoteric linkers; it's been tested on macOS and Linux.

The Python and OCaml bindings depend on being able to build the C code. See libdash.opam for details on the OCaml code's dependencies, which includes the build-time external dependencies. Python wheels have no need for these build-time dependencies, but building from a Python source distribution will only succeed when libtool and autotools are present.

The CI scripts (in .github/workflows/build.yml) give build details.

How to build libdash from source

Python

Run python3 setup.py install. On macOS, you must first install the build dependencies via brew install libtool autoconf automake.

You can test the Python bindings by running:

cd python; make test

OCaml

Install the OPAM file: opam pin add . or opam install .. This will build the OCaml library and install it in your OPAM repository. There are tests in another directory; they will only build when libdash is actually installed.

You can test the OCaml bindings by running:

cd ocaml; make test

Testing

The tests use test/round_trip.sh to ensure that every tester file in test/tests round-trips correctly through parsing and pretty printing.

Additionally, you can run tests that compare the OCaml and Python implementations (after you've installed them both):

cd test; make

How to use the parser

For Python, see python/rt.py, an example tool that does a round-trip: shell syntax to AST back to shell syntax.

For OCaml, see ocaml/shell_to_json.ml, a tool that parses shell syntax and produces JSON (using the atdgen bindings).

The ideal low-level interface to use is parsecmd_safe in parser.c; you'll need to ensure that dash's initialization routines have been called and that the stack marks are managed correctly. Parsing the POSIX shell is a complicated affair: beyond the usual locale issues, aliases affect the lexer, so one must use setalias and unalias to manage any aliases that ought to exist.

How work with the parsed nodes

The general AST is described in nodes.h. There are some tricky invariants around the precise formatting of control codes; the OCaml code shows some examples of working with the args fields in ocaml/ast.ml, which converts the C AST to an OCaml AST.

The OCaml tools shell_to_json and json_to_shell will produce JSON ASTs, allowing you to work with these ASTs in any language.

Pretty printing

The pretty printer does its best to produce valid shell scripts, but it's possible to manually construct AST nodes that don't directly correspond to valid scripts.

For example, the Python AST [[['Q', [['C', 34]]]]] represents a quoted field containing a double quote character. Translated literally, this would yield the string """, which is not a valid shell script. The pretty printer will instead automatically escape the inner quote, rendering "\"".

While the printer tries to get things right either way, you should use escapes to signal to the printer when to escape: you should use the Python AST [[['Q', [['E', 34]]]]] to mark the inner double quote as escaped.

Known issues

We currently do not escape the character ! (exclamation point). In an interactive shell, ! is likely treated as a history substitution (and so should be escaped), but in a non-interactive shell, ! is treated normally. We currently cater to non-interactive shells; eventually this behavior will be controllable.

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

libdash-0.4.1.tar.gz (182.8 kB view details)

Uploaded Source

Built Distributions

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

libdash-0.4.1-cp314-cp314t-musllinux_1_2_x86_64.whl (270.7 kB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ x86-64

libdash-0.4.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (280.6 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

libdash-0.4.1-cp314-cp314t-macosx_11_0_arm64.whl (159.5 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

libdash-0.4.1-cp314-cp314-musllinux_1_2_x86_64.whl (270.7 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

libdash-0.4.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (280.6 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

libdash-0.4.1-cp314-cp314-macosx_11_0_arm64.whl (159.5 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

libdash-0.4.1-cp313-cp313-musllinux_1_2_x86_64.whl (270.7 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

libdash-0.4.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (280.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

libdash-0.4.1-cp313-cp313-macosx_11_0_arm64.whl (159.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

libdash-0.4.1-cp312-cp312-musllinux_1_2_x86_64.whl (270.7 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

libdash-0.4.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (280.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

libdash-0.4.1-cp312-cp312-macosx_11_0_arm64.whl (159.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

libdash-0.4.1-cp311-cp311-musllinux_1_2_x86_64.whl (270.7 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

libdash-0.4.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (280.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

libdash-0.4.1-cp311-cp311-macosx_11_0_arm64.whl (159.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

libdash-0.4.1-cp310-cp310-musllinux_1_2_x86_64.whl (270.7 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

libdash-0.4.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (280.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

libdash-0.4.1-cp310-cp310-macosx_11_0_arm64.whl (159.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

libdash-0.4.1-cp39-cp39-musllinux_1_2_x86_64.whl (270.7 kB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

libdash-0.4.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (280.6 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

libdash-0.4.1-cp39-cp39-macosx_11_0_arm64.whl (159.5 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

libdash-0.4.1-cp38-cp38-musllinux_1_2_x86_64.whl (270.6 kB view details)

Uploaded CPython 3.8musllinux: musl 1.2+ x86-64

libdash-0.4.1-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (280.4 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

libdash-0.4.1-cp38-cp38-macosx_11_0_arm64.whl (159.6 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

Details for the file libdash-0.4.1.tar.gz.

File metadata

  • Download URL: libdash-0.4.1.tar.gz
  • Upload date:
  • Size: 182.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for libdash-0.4.1.tar.gz
Algorithm Hash digest
SHA256 7358384499f7ce9c9fd8e07904e655945107b5e5eebff490651dfad62491c175
MD5 0bad2275947d6760f9eee85dccd8f5aa
BLAKE2b-256 ce2ca0e4b20b6519acca782262227aeef690ac3b0aad305a838286c423afa9d7

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp314-cp314t-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b2d545f9294e629842275458be907213b0ee7cf35a18293ad8137fe53fac7417
MD5 cd5f51cb0e6c70366c3b13f166eaf25f
BLAKE2b-256 1ecf6a374fff47098d656970bcbecaf291771d1fa66b0c0a1f46a273d43be34e

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ea6bd4aa1bddd6e11a9c2b67bdf9762afe473c2759530bdb5d9bb130cf590b7e
MD5 46ddfbe30b4f82a474671f5baa927306
BLAKE2b-256 ff834dd4d30079942cb92b1d7051d81debaf3ca0c6eed6644a61a4e6a8c95420

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 93cdec29e73ab376528511cd6baede26424c4f11add9a1468c5943b61c45703f
MD5 2c3740953dc227633bc84f53a3cc8394
BLAKE2b-256 7b5db5e6e5b0144625ae66b3dbc55cab4373d0b56aa97e7748c631f084b24f19

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a69879b282fa9cf1bfdec99b617af313a496bc4395f9dc452aa153044c951d45
MD5 94cafa12b270c3be13c472e8d979a873
BLAKE2b-256 75d43dfcf667fd33b571de5a377c19e4950ec266e7931e01a33061297ac04898

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b35524f091c9aa287f01e8275ef00c40d23bcccbd486fc2d5b40cb2875409ddf
MD5 d4b3cd4b66a95df885841e8eb744aaad
BLAKE2b-256 60e4c2dcab6d1753a0299f9dcefc1de0864c7c5d76404caef0c1d42da57ce2a0

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 28a6a4e0103700385a72e6046767d0d91cdeb2de8393c6443e136b30ac4b8730
MD5 cba278235bf2277e6e6991504d50a044
BLAKE2b-256 3faef48e3410e89dbc5f8ab59125b7f26a2be9a2e57510b8a058992e396b7b29

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c49abc9c2c774725d23d12d28d895618558a2bdb7bc7cbc0cb6f279e79249ae6
MD5 53c1cc02263c28f12bc4806a73f0bb9d
BLAKE2b-256 51cba2e6ca49cbce0c6a5ba1f953f47cd0f4fa9a7aaf623e24e28801f683f75c

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bea5e6baf3daa25960c99598d99b1e942376ab04eac305f307b74a2ce0beb741
MD5 578725362c9eb9a88986b7354d0654ad
BLAKE2b-256 37bb9b10249e75d7d0e903f27603c1c69f6cf0b9344ff18d82f09bd6207fac2a

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f85f22eb8592bf222c217113723a6438686aaed3107eb4b3cd58fb94540ad77d
MD5 ad6902171cb6c53e0700e915539ca59b
BLAKE2b-256 da213cb9e88bc8a50c07e427705b37b03a511edc135ed7df2cc51f67bb6ffc6c

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 35cb7d32713f61147e26d203e3013facc734ccd24f734900a332d89a065535d3
MD5 bdf6bc832af9178b258644bc057e595a
BLAKE2b-256 8642e58889549c108423d7e36bdaef311786b7fede2f6c1adc43ccd2fc94a099

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8ce02d9bc60d8eeece7fb1f8061b8aa6db33f2c1c71450c069bff2976e7126fa
MD5 00fe393eba690eeaa2b5f04ab91b9358
BLAKE2b-256 b01bd51f8aa9614eed8d1ea9333e63f2d63c2e0be796d004a655a53194b0270c

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b5121386729259cb56ee56e5664c1fd6cab6b08127487946f0fa5ae244aab5d1
MD5 cf8329b942df9d75d7f56dd5a52b0393
BLAKE2b-256 5b2e474ef42160fd841f158b9eb546c58841f150054b99589d6ec6bbe2a978d4

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 71ff1acf57d7663953c27ec51380eda5e6adbbb4e3815d26158b7cf44e93285e
MD5 23fe7030d47883c094a01338c16a6202
BLAKE2b-256 95d3f15105ac373d24078fa2d82bcbef4c9d979d9b75752ec448298f86e897fa

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7c4aaf9dd10ffeaae674eafdab4772518d164fa1d66c7b06039d43d41636a7c5
MD5 b9123291ce1d5087c6f9d354ca526325
BLAKE2b-256 7f24c7b56628eee4b09f06e02ed1ae38ac5e9eb951fabe398c6266969fefb533

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 791e56b83458e8fb656bc2f5bd142780ca9b6cef06f7e9f31b4c6f4628657e8a
MD5 a5159a987d2a8091d9de6aca9c4fd038
BLAKE2b-256 7f0520058679eaba1fa543a596fc73c3eab926beb6a0f018458078cec51421f2

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 80a7e518221173500e7190be96ad56c3cc3fdd96b3fec744685d333bd6cf5e22
MD5 2afc25b2211d66a2f92a78acdf972c25
BLAKE2b-256 ae863b65907c47f867d580201748dcf7cefcde7ef5967ce24fe87261d3b06b10

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8bfa837911e49b2280fcd3afd323145f635cc79914cb28d75ba960864a623196
MD5 7c0a49d18a491f43d51736f55e0946d3
BLAKE2b-256 95eedf453a928ef2c585862e9a4362ee1e7660a3fc5d36d450a142714b13a92d

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 006e121f67f19cfa9e323694e2ed54e34ef106649a88cf073da1794a57731a86
MD5 cd4f21b51c2450a6d6c56ddb961ac3d3
BLAKE2b-256 d32a5a36dac9ee3a40b757993d420b3193d02e16eba5ea189b02d11de47f55df

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2e17caed7aa5d1c0a4eb1023da857c70ad36e8f4b5d80aaa289996063df62e44
MD5 0e674317d488d43d30462a5e7147d3e8
BLAKE2b-256 a0a904b3bee103400cce837a057a5023127636317e689eb608034a51f271bffb

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 67e889441c2f73c5d8e1561a57ee321cc2a38ced242d57e3198a5aebd7b1ac85
MD5 d60af054a802b80a7508cded53c87251
BLAKE2b-256 ee8c0df04be90543af55023f53b1a26eaf41cab217d5fc89062dcf06a7a14f8d

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c644009cb4a21d20f059c1d323574cd70ff844026abfacbb15ae9343d2558961
MD5 1c06b4f30059ff8b85db4cdad060f29c
BLAKE2b-256 57f48250b01f4250d183ac9328f8dad834a078a46a073ea231f2518ab59d5ced

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp38-cp38-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 13864d4a8f7e350bce75327c19f4f3bfaa1c58cd07e5b7159a246120853c6993
MD5 4fe1976730478609875875b61e69cfb0
BLAKE2b-256 a2e2305926c29d8e384133c5c94dbee6fb64d90c80bf8df0f0c43c5d7295f196

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d42e7752bfab2bd1c57614ebe30cc12fa33b2d4007909180e5fea7c2685c7acf
MD5 9272b2bec2a244719d8a6ffcad2ffd57
BLAKE2b-256 55275e6902f61d550ff692201e513ed2029b8f08e83c7b900a1a7a1ee6c82295

See more details on using hashes here.

File details

Details for the file libdash-0.4.1-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for libdash-0.4.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 31d527e3494d5081f4a9437a758b5b74defe3d5c565b9c73a934f890d80f9689
MD5 6f17638082dd24f4e615f4cff5b6466f
BLAKE2b-256 12151e3d5f56364ebd2fc3336344d2e313f749efec38580258bd34b28f777184

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