2017-08-01 57 views
0

我試圖將~/.aws複製到我的碼頭集裝箱中。但是我在運行git-bash的Windows機器上,這似乎是導致一些問題。如何在npm腳本中以跨平臺兼容的方式使用〜(home dir)?

兩件事至今我已經試過:

"d-aws-copy": "docker cp ~/.aws constraint-listener:/usr/src/app"

結果:GetFileAttributesEx C:\work\project-name\~: The system cannot find the file specified.

"d-aws-copy": "docker cp /c/Users/user-name-here/.aws constraint-listener:/usr/src/app",

結果:GetFileAttributesEx C:\c: The system cannot find the file specified.

所有我見過涉及波浪線之後的解決方案擴展是針對節點代碼的,而不是針對命令行的npm腳本。

如果我從bash運行docker cp ~/.aws constraint-listener:/usr/src/app它工作正常。但是在一個npm腳本中,它會像上面看到的那樣崩潰。

我怎樣才能讓~在Windows機器上的npm腳本中工作?

+0

我認爲這應該對你有所幫助:https://stackoverflow.com/a/9081436/1262789 – Bhavyanshu

回答

0

解決方法是直接調用bash

"d-copy-aws": "bash -c \"docker cp ~/.aws constraint-listener:/root\" && echo aws credentials copied", 
0

當從節點呼喚你使用的是標準的外殼,大概CMD在Windows上。它不會對字符串進行字符串內插。改用平臺獨立變量或檢測平臺,並使用process.env查找$ HOME或$ WINHOME的值 - 具體取決於操作系統。

編輯:沒有看到它是一個NPM腳本...錯過了標籤。思考了Node提到的問題。

相關問題