Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
97 views
in Technique[技术] by (71.8m points)

javascript - 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:

  "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/[email protected] 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?

question from:https://stackoverflow.com/questions/65660483/copying-multiple-files-in-the-same-directory-using-a-package-json-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

% echo $0
zsh

Running npm from the same interactive shell:

% npm run shell

> [email protected] shell /so/so65660483-npm-shell
> echo $0

sh

cp supports copying multiple files without relying on shell globbing in any case:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...