shelljs / shx

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

echo works differently in Win #192

Closed hcfw007 closed 2 years ago

hcfw007 commented 3 years ago

I have a npm script like this

{
  "scripts": {
    "fixup": "shx echo {\"type\": \"commonjs\"} > dist/cjs/package.json"
  }
}

when calling it on Mac Os

> fixup /.../
> shx echo '{"type": "commonjs"}' > dist/cjs/package.json

it works properly. the content of the target package.json is

{"type": "commonjs"}

however in Win, maybe something is wrong when converting quotations.

> ... fixup
> shx echo '{"type": "commonjs"}' > dist/cjs/package.json

the content of the target package.json is

'{type: commonjs}'
nfischer commented 2 years ago

What version of node and npm are you using?

This looks like an npm bug. Npm appears to be adding single quote characters into your command. Single quotes change the behavior on Windows. There's nothing shx can do to workaround this since it's just executing the command is it was received (and you'll notice in the npm output that shx receives a command with single quotes).