无法在Powershell中运行以下Bash/Zsh命令:
$KeyPath = Join-Path -Path $this.Plate -ChildPath "install/tekton.key"
kubectl create secret docker-registry regcred `
--docker-server="https://gcr.io" `
--docker-username=_json_key `
--docker-email="name@org.iam.gserviceaccount.com" `
--docker-password="$(cat $KeyPath)"我得到了错误:
error: exactly one NAME is required, got 5
See 'kubectl create secret docker-registry -h' for help and examples如果我在bash中直接运行这个命令,它可以工作:
kubectl create secret docker-registry regcred --docker-server="https://gcr.io" --docker-username=_json_key --docker-email="name@org.iam.gserviceaccount.com" --docker-password="$(cat ./tekton.key)"发布于 2020-04-16 12:09:10
我不知道这是否是你问题的原因,但是有两个
包含空格的
重新构建命令行时将参数作为一个整体引用。
- For instance, if `$(cat $KeyPath)` (`$(Get-Content $KeyPath)`) expands to `one two`, PowerShell passes `"--docker-password=one two"` behind the scenes, _not_ `--docker-password="one two"`.
- Whether this changes the meaning of the argument depends on how the target program parses its command line - I don't know what `kubectl` does. - If you do need to address this, escape the enclosing `"` (double quotes) with `` ``` (the backtick, PowerShell's escape character to make PowerShell pass your argument in the original syntax form: - `--docker-password=`"$(cat ./tekton.key)`"`
- Note that - unlike in POSIX-like shells such as Bash and Zsh - you normally do _not_ enclose a variable reference or subexpression in `"..."` in order to pass it through safely; e.g., `--foo=$someVar` or `--foo=$(Get-Date)` work fine, even if `$someVar` or the output from `Get-Date` contains spaces or wildcard characters.
$KeyPath 包含多个行,这些行与参数中的空格连接在一起:H 233F 234- For instance, if the file contains `"a`nb`n"` (`"`n"` being a newline), PowerShell will pass"--docker-password=a b.
-相反,类似POSIX的shell(如Bash或Zsh )将保留内部换行符,同时裁剪(任意数量)尾随行。
顺便提一句:PowerShell在传递给外部程序的参数中对嵌入式双引用的处理是失败的--参见this answer。
https://stackoverflow.com/questions/61249289
复制相似问题