我想将逗号分隔的值列表作为单个开关的一部分传递到脚本中。
这是程序。
param(
[string]$foo
)
Write-Host "[$foo]"
这是用法示例
PS> .\inputTest.ps1 -foo one,two,three
我希望该程序的输出为
[one,two,three]
,但它返回[one two three]
。这是一个问题,因为我想使用逗号来定义值。为什么Powershell删除逗号?为了保留它们,我需要更改什么?
最佳答案
逗号是powershell中的特殊符号,用于表示数组分隔符。
只需将参数放在引号中:
inputTest.ps1 -foo "one, two, three"
或者,您可以“引用”逗号:
inputTest.ps1 -foo one`,two`,three
关于powershell - Powershell正在从程序参数中删除逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11990688/