Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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/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?


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

1 Answer

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

> 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 target/sitemap.xml target/robots.txt ../fs-dtest-app/

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...