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.0.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.0-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.0-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.0-cp314-cp314t-macosx_11_0_arm64.whl (159.5 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

libdash-0.4.0-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.0-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.0-cp314-cp314-macosx_11_0_arm64.whl (159.5 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

libdash-0.4.0-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.0-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.0-cp313-cp313-macosx_11_0_arm64.whl (159.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

libdash-0.4.0-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.0-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.0-cp312-cp312-macosx_11_0_arm64.whl (159.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

libdash-0.4.0-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.0-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.0-cp311-cp311-macosx_11_0_arm64.whl (159.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

libdash-0.4.0-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.0-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.0-cp310-cp310-macosx_11_0_arm64.whl (159.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

libdash-0.4.0-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.0-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.0-cp39-cp39-macosx_11_0_arm64.whl (159.5 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

libdash-0.4.0-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.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: libdash-0.4.0.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.0.tar.gz
Algorithm Hash digest
SHA256 5fc46682221af67dd1988fbff4b0cf0b4548dab8375d33696d1769a60ff25abd
MD5 8fd54a00dc322deb08dca70de90fc682
BLAKE2b-256 b887c96ee4636d2f2cacb058aecca3c7b8a3ddaefa2a3cc89616b1afcc8d32d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fe41d1962bf06bc757bf7bc789675b155df024f23f41aae7e813f4929efcb79c
MD5 4ea4f9d855c99a468bfca22facd8b95e
BLAKE2b-256 99656af0d3eab55f3aaa2b493d83498d2330a2d6096f4008ced0eaef6886a940

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5a1fd5301a45abec177a745b4d1ada813aa728415b25f800eff2d06aab374340
MD5 158973e883b6615836e3b0577fc521e2
BLAKE2b-256 54a810d02f67a995bcb08c2b8056cf184644b8a701798874c0c0ba307288fde6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3e678fde0bc6e2303d8b780bb6c43473bec33d0745fb3391d958ea17795ce534
MD5 4cf56688db1190af3de261532b2fe1af
BLAKE2b-256 4566b46966c83b4eb56c553eedcc32c4216be44f0f736a53b9cb8a49dc93c573

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a29df1f45d20b7b9c317548ec949fd7886ed70d101a552fbf9db3f7e6cb688cc
MD5 9311bccf7e17049e9972f7330c366453
BLAKE2b-256 fa6f549007c2f9e0ec8d2b70c2072bd6e43d95881c78b9b04824b31965f0e05b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 178e810d683482263cdda2fb1b60ab005dcc575faa1c13d0ff4c76f643e59332
MD5 2d91764badbf00553ae88a95e589ff70
BLAKE2b-256 7727211502022b35f94dc831c155a9cbd995252dad5eb4bad213c41263396e58

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d6bb1da985ff49cb9b5ef94b577a1979a9e05ba6c5b244c0395143f50745011b
MD5 22bedcfa64d584a708cd7d344005b81e
BLAKE2b-256 5c25c9844cc8f160f2c92d1f799fba4b18e1bc03f02c4d4614c3393741a32908

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2150632681782a6edb62c0373919f2a79dae5e8300801a1c42360384291697e8
MD5 286c7dc8ebceba4d2a0df30a89276d89
BLAKE2b-256 39e8926f2f6854afb7cc0f9dd4fdb5ae629b555a1677abe0e2ee0e58021204c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ba0aab182b5882e4450f2c71d00a27b27bd9e377c02ad6c642f829e11e30958d
MD5 09961c0d2aad83ff01df6c88b0008a2b
BLAKE2b-256 7fea921e8fe23150ee474e518949965b8ba67811ed0e29dcad76197a59bc85a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 58d028b0b680283cc001dc2a80d4478a54d640ad56826b5d7c4ef79f5e9d6ce9
MD5 e0486e25948161d5b7e8b6b76191595c
BLAKE2b-256 faddece7c849311ddcca8a5e8e568ae5258d03d22423cd91df150dc74bbca49d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 936e09b607860e8d5ef26d4f4f70cc7c89235ccb63d43b7e792f3692f356b543
MD5 8112fde9945e6d6a352b2c7e4e27f1e9
BLAKE2b-256 ac6bc1d9e6e5042dd5bab27890654a6ea6a711210281b9d8aa258d3cf6f5b109

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5b1757f57768e05b110e6eacf0e44c26624e3ba824542954bd08f9d5589600cf
MD5 28c0f2c08fa98972291e10bbaa3b7de2
BLAKE2b-256 259af2604e39ca445a40724d09a442a850a527ab59903ea1e448152d6065e494

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5545af8a91460c236a86014bf2acdaa31a2d6d09ff65a2ebcf2868fa1108fa93
MD5 7f7e8df97d65b2812973dc43160cc933
BLAKE2b-256 5ab9947be535aef337b18036ecc007581faf8d5a3feb378d0e8d8ff2193b6a8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e27802ad5604cf53dcb5a86378298b4602ff4de174b95f1e9dabef94c794780d
MD5 1af1f7be3be781cf5224092c7f1ddd04
BLAKE2b-256 7d3fca3787788d424bd0e4ab5b165f362353dbedc43d6dcab8159c6c3b35f1ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cdd2fede8a1fbc99245dfc732933bc4631fcc63dfc8bf646491e11e780a0f8e8
MD5 c1e7254d821988038cd9f98cc1db451e
BLAKE2b-256 3d1a25ebdf91b6a27a21532bbeed1929707d431a9dba05cc8e3aba682aeda4fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5e0dcdd148d9dac0b3990dca9c9dafab0408c3f266f69e941c8eca7ba205a86d
MD5 faa161e9c491a4ad409f492440b6bce1
BLAKE2b-256 eb8efb4ed3886a2661cd5c4d00f39b55980ef89f7fa0965033a13e3b23b420e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 025cf34bff3a95fb98388e35e473efb8229818363f158cfc064b791dd28b14b3
MD5 c02d500326e98317a6776d93cd740cd9
BLAKE2b-256 f55d1c867c8709cbbd4ce182f32de2bfea3573b7af050381926b9d15d4453fca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f41c4d86a938a41c81141d6e50a81078c6fdc21198f2f6ae67cc46096bf88c29
MD5 62ec6c95ebd839590d103da2c8958147
BLAKE2b-256 1251056efc04cb8fad2fa204c0fd08d0410c5b9272b7039deea171d55e74cef0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b0a7d0440a72f4c4b7969b192ff49cac084f766ec147c546f1878f1e016f2be7
MD5 8ebb90c265d939751e8bac14c2bc3bcb
BLAKE2b-256 457e27f61f6e9b01df4c639d9727c9e283932c8fc1fb0a001b4813beff49c1a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 126a8d098206b0113ba44301d0f0e04e1477d3908d4e87f8ceea2beb48fbb924
MD5 f7f3b05e7502ea5fcfaa0388d063e43c
BLAKE2b-256 43237e55f13a1d3ebec795238fe9866c3b49b8702223f7dc21d039d2b79f6ead

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2113b18a01685a11c8592043eff92ae50173be6fc68a28f30f35e551ff85b7c0
MD5 5befcb84435e5b2d6e5b0cc4921fd02b
BLAKE2b-256 73a31e4ead6cbd114d7b8a443dc97ebaf45b0696d458ed3faeb69734776c41b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 34c9ebffd075c934973c268f5795192c5d4ffecc8d87d5f9f64c7eb9ac65f033
MD5 10591a36dae1a2d2cd981ee1a5db406a
BLAKE2b-256 edaf9931a71e5fe9790873065866f2d3740165417e07320dbcb3840f4d35500c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7064baea2b8f19518a6423fc848c462089932dc7c114c53f255e45dc37a746db
MD5 329b53601e5a81081dc41b3d222bf363
BLAKE2b-256 c277660192f5f0a6fecba74a2a29d9f3f1f349ea0cfc40ba6a89bfe6cf23fd49

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6680b34b1dd360226e651d1f92540e8e829a29f0600a19d2303d5883b26e2e23
MD5 f89ef3e05c2cbc7943a1abc22d2a2e28
BLAKE2b-256 d0fe230342c79871b482bd7444ca2e752be808dfd8940e3546d4a0184a9e23d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for libdash-0.4.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0c124354fcd923ac7e1954badb54971396c326dac0a3de246fa1f98208f198cd
MD5 200196bca7e057f18dd39875ab9de394
BLAKE2b-256 bf21b65303073e9a0ed0e529956fc45e8f65de436b10c757e1c1e69d65c54dd8

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