简体   繁体   English

使用 package.json 脚本在同一目录中复制多个文件?

[英]Copying multiple files in the same directory using a package.json script?

This works on the command line:这适用于命令行:

cp target/{sitemap.xml,robots.txt} ../fs-dtest-app/

But if I put the command inside a script tag in package.json like this:但是,如果我将命令放在package.json中的脚本标记中,如下所示:

  "scripts": {
    "c": "cp target/{sitemap.xml,robots.txt} ../fs-dtest-app/"
  },

This happens:有时候是这样的:

ole@mkt:~/Temp/dtest/fs-dtest-md$ cp target/{sitemap.xml,robots.txt} ../fs-dtest-app/
ole@mkt:~/Temp/dtest/fs-dtest-md$ npm run c

> @fireflysemantics/fs-dtest-md@1.0.1 c /home/ole/Temp/dtest/fs-dtest-md
> cp target/{sitemap.xml,robots.txt} ../fs-dtest-app/

cp: cannot stat 'target/{sitemap.xml,robots.txt}': No such file or directory

Thoughts?想法?

npm will use the /bin/sh Bourne shell implementation rather than the current interactive shell of a user, whatever that may be (or cmd.exe on MS platforms). npm will use the /bin/sh Bourne shell implementation rather than the current interactive shell of a user, whatever that may be (or cmd.exe on MS platforms).

In an interactive zsh shell:在交互式 zsh shell 中:

% echo $0
zsh

Running npm from the same interactive shell:从同一个交互式 shell 运行npm

% npm run shell

> so65660483-npm-shell@1.0.0 shell /so/so65660483-npm-shell
> echo $0

sh

cp supports copying multiple files without relying on shell globbing in any case: cp在任何情况下都支持复制多个文件而不依赖 shell 通配符:

cp target/sitemap.xml target/robots.txt ../fs-dtest-app/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM