shelljs / shx

Portable Shell Commands for Node
MIT License
1.72k stars 44 forks source link

Unable to output escaped double quotes using shx echo #178

Closed doberkofler closed 4 years ago

doberkofler commented 4 years ago

The following example shows that shx echo does not seem to output the escaped double quotes (at least) on the Windows platform:

{
  "name": "shx-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "shx echo Usage: node runSelenium.js \"**/BasePage--test.ts\""
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "shx": "^0.3.2"
  }
}
nfischer commented 4 years ago

That's equivalent to running any of the following in your shell:

$ shx echo Usage: node runSelenium.js "**/BasePage--test.ts"

If you want quote literals in the output, you need:

$ shx echo Usage: node runSelenium.js '"**/BasePage--test.ts"'

Which translates to:

{
  "scripts": {
    "test": "shx echo Usage: node runSelenium.js '\"**/BasePage--test.ts\"'"
  }
}
doberkofler commented 4 years ago

Thank you. This works on macOS and Linux but on the Windows platform the output wrongly shows the single quotes: Usage: node scripts/runSelenium.js '**/BasePage--test.ts'.

nfischer commented 4 years ago

Then you'll need to rewrite it with double-quotes (that's a Windows issue, before shx ever starts executing). I think this should work cross-platform:

{
  "scripts": {
    "test": "shx echo Usage: node runSelenium.js \"\\\"**/BasePage--test.ts\\\"\""
  }
}
doberkofler commented 4 years ago

Perfect. Thank you!