[英]PowerShell: how to pass , as a string from command line to a powershell sciript
[英]Unable to pass value from command line to Object - Powershell Paramter
我试图弄清楚如何将Powershell中包含特殊字符的参数传递给函数内的对象。 这是我的代码示例。
function a{
param(
[string]$string
)
#convert to URL encoding here
#Query API
#Return JSON values
}
现在我在Powershell中输入
PS> a foo(foo; bar) foo/bar ver1.0
并为“;”错误触发 然后“)”成为字符串的一部分
这是错误:
At line:1 char:32
+ a foo(foo; bar) foo/bar ver1.0
+ ~
Missing closing ')' in expression.
At line:1 char:41
+ a foo(foo; bar) foo/bar ver1.0
+ ~
Unexpected token ')' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndParenthesisInExpression
我有两种选择。
使用单引号:
a 'foo(foo; bar) foo/bar ver1.0'
或转义所有特殊字符:
a foo`(foo`;` bar`)` foo/bar` ver1.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.