文件夹中带有$ npm_package的npm脚本,路径中有空格

时间:2019-08-31 17:14:16

标签: macos shell npm

package.json:

{
  "name": "app",
  "version": "0.1.0",
  "private": true,
  "folders": {
    "plugin": {
      "dist": "\"/Users/User/Google Drive/App/Dist/plugin\""
    }
  },
  "scripts": {
    "remove_shared_dist": "rm -rf $npm_package_folders_plugin_dist"
  }
}

我要删除以下文件夹:/Users/User/Google Drive/App/Dist/plugin
我用\"包裹了它的路径,以使外壳程序接受带空格的文件夹名称。但只能打印

rm -rf $npm_package_folders_plugin_dist

什么也没做。
如果我在终端中运行rm -rf "/Users/User/Google Drive/App/Dist/plugin"-它将按预期方式删除该文件夹。
我在macOS上

1 个答案:

答案 0 :(得分:0)

@戈登·戴维森({Gordon Davisson)对正确方向的评论hinted me

{
  "name": "app",
  "version": "0.1.0",
  "private": true,
  "folders": {
    "plugin": {
      "dist": "\"/Users/User/Google Drive/App/Dist/plugin\""
    }
  },
  "scripts": {
    "remove_shared_dist": "bash -c \"rm -rf $npm_package_folders_plugin_dist\""
  }
}