shell-parser

1.0.0 • Public • Published

shell-parser

Parses a string similarly to how POSIX shells parse command lines into arguments, and returns an array of strings that correspond to the parsed arguments. Quoting and escaping are supported.

const shellParser = require('shell-parser');

Examples

> shellParser('ab cd ef');
[ 'ab', 'cd', 'ef' ]
> shellParser('ab "cd ef"');
[ 'ab', 'cd ef' ]
> shellParser('a "" b');
[ 'a', '', 'b' ]
> shellParser("'a'\\''b'");
[ 'a\'b' ]
> shellParser('a "bc');
Thrown:
Error: Unterminated quote: "
    at quoted (/home/chris/dev/shell-parser/index.js:47:19)
    at shellParser (/home/chris/dev/shell-parser/index.js:88:18)

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    163
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    163

Package Sidebar

Install

npm i shell-parser

Weekly Downloads

163

Version

1.0.0

License

MIT

Unpacked Size

5.54 kB

Total Files

6

Last publish

Collaborators

  • cdhowie