shelljs / shx

Portable Shell Commands for Node
MIT License
1.73k stars 45 forks source link

Can't get globs to work with `rm` #213

Closed matthew-dean closed 1 year ago

matthew-dean commented 1 year ago

I'm trying to run this NPM script:

shx rm -rf '**/node_modules/' && shx rm -rf '**/package-lock.json'

However, this seems to exit without recursively removing those directories / files.

matthew-dean commented 1 year ago

oh wait! I got it working with:

"clean": "shx rm -rf \"**/node_modules/\" \"**/package-lock.json\""
nfischer commented 1 year ago

Huh, that's strange. I get the same behavior with double quotes or single quotes. I'm testing this on Ubuntu with npm 8.5.1 and nodejs v12.22.9:

  "scripts": {
    "testquote": "shx ls 'node_modules/**/index.js'",
    "testdoublequote": "shx ls \"node_modules/**/index.js\""
  },

I also noticed you changed that from 2 rm commands to use just 1 rm command with 2 arguments. I think either should work, but maybe there's some race condition I'm not thinking about with the two commands.

nfischer commented 1 year ago

I should add: I think Windows does not honor single quotes (it treats them like they're part of the file name). So if you want this to be cross platform, then I recommend you use double quotes (exactly like you did in your last update).