簡體   English   中英

無法將值從命令行傳遞給對象-Powershell參數

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM