Skip to content

Instantly share code, notes, and snippets.

@polotek
Created May 28, 2012 23:06
Show Gist options
  • Save polotek/2821573 to your computer and use it in GitHub Desktop.
Save polotek/2821573 to your computer and use it in GitHub Desktop.
Testing @substack's shell-quote lib for parsing cli arg strings
var s = require('shell-quote');
console.log(s.parse('"foo = \"foo\""')); // [ 'foo', '=', 'foo' ]
// this is what I want
console.log(s.parse('"foo = \\"foo\\""')); // [ 'foo = "foo"' ]
// why does this also work? shouldn't it have slashes in it?
console.log(s.parse('"foo = \\\"foo\\\""')); // [ 'foo = "foo"' ]
Copy link

ghost commented May 28, 2012

Javascript quotes are getting in the way with the last example. It works fine if you read the string from a text file instead:

s.txt:

echo "foo = \\\"foo\\\""
var parse = require('shell-quote').parse;
var fs = require('fs');
var src = fs.readFileSync('s.txt', 'utf8');
console.dir(parse(src));

output:

[ 'echo', 'foo = \\"foo\\"' ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment