问题描述
我想将逗号分隔的值列表作为单个开关的一部分传递到脚本中.
I want to pass in a comma separated list of values into a script as part of a single switch.
这是程序.
param(
[string]$foo
)
Write-Host "[$foo]"
这里是使用示例
PS> .\inputTest.ps1 -foo one,two,three
我希望这个程序的输出是 [one,two,three]
但它返回的是 [one two Three]
.这是一个问题,因为我想使用逗号来分隔值.
I would expect the output of this program to be [one,two,three]
but instead it is returning [one two three]
. This is a problem because I want to use the commas to deliminate the values.
为什么 powershell 会删除逗号,我需要更改哪些内容才能保留它们?
Why is powershell removing the commas, and what do I need to change in order to preserve them?
推荐答案
逗号是 powershell 中用来表示数组分隔符的特殊符号.
The comma is a special symbol in powershell to denote an array separator.
只需将参数放在引号中:
Just put the arguments in quotes:
inputTest.ps1 -foo "one, two, three"
或者,您可以引用"逗号:
Alternatively you can 'quote' the comma:
inputTest.ps1 -foo one`,two`,three
这篇关于Powershell 正在从程序参数中删除逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!