Skip to content
vic

grncdr/js-shell-parse

parse bash, with javascript (UNMAINTAINED)

grncdr/js-shell-parse.json
{
"createdAt": "2013-12-27T23:40:15Z",
"defaultBranch": "master",
"description": "parse bash, with javascript (UNMAINTAINED)",
"fullName": "grncdr/js-shell-parse",
"homepage": "",
"language": "JavaScript",
"name": "js-shell-parse",
"pushedAt": "2018-12-21T17:48:34Z",
"stargazersCount": 92,
"topics": [],
"updatedAt": "2025-05-06T13:53:57Z",
"url": "https://github.com/grncdr/js-shell-parse"
}

Parse bash scripts into AST’s

var parse = require('shell-parse')
parse('echo $PATH') //=> an ugly AST object

(better synopsis will come after real tests)

This thing parses strings containing bash scripts into an AST that you might execute using an interpreter or something. The AST structure is still in flux, so you probably don’t want to build on this just yet!

If you want to help, there’s a whole bunch of failing test fixtures (borrowed from the lovely shellcheck project). You can start with reading the [grammar]!(grammar.pegjs). The grammar defines how text will be matched, while the corresponding rule callbacks in [overrides.js]!(overrides.js) defines the way those matches will be processed into AST nodes. Be sure to read the comments as there’s a tiny bit of magic going on.

If you get stuck trying to fix a test case, email me. GitHub issue notifications almost never get my attention.

See [the tests]!(tests) for all the things that can be parsed.

MIT