Skip to content

cdhowie/shell-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shell-parser

Build Status npm

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)

About

Parse a command line into arguments similarly to a POSIX shell

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published