但这是错-6ren">
gpt4 book ai didi

powershell - 如何将带有空格的字符串传递到PowerShell中?

转载 作者:行者123 更新时间:2023-12-04 02:52:12 24 4
gpt4 key购买 nike

鉴于:

# test1.ps1
param(
$x = "",
$y = ""
)

&echo $x $y

像这样使用:
powershell test.ps1

输出:
> <blank line>

但这是错误的:
test.ps1 -x "Hello, World!" -y "my friend"

输出:
Hello,
my

我期待看到:
Hello, World! my friend

最佳答案

好吧,这是一个cmd.exe问题,但是有一些解决方法。

  • 使用单引号
    powershell test.ps1 -x 'hello world' -y 'my friend'
  • 使用-file参数
    powershell -file test.ps1 -x "hello world" -y "my friend"
  • 使用以下内容创建.bat包装器
    @rem test.bat
    @powershell -file test.ps1 %1 %2 %3 %4

    然后调用它:
    test.bat -x "hello world" -y "my friend"
  • 关于powershell - 如何将带有空格的字符串传递到PowerShell中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28311191/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com