Param ( [parameter(Mandatory=$true)] [alias("-my-param","p")] [String] $param)
我希望这是电话
c:\src\ps\params.ps1 --my-param "x"
将被认为是指别名-my-param.不幸的是,我得到的是
C:\src\ps\params.ps1 : A positional parameter cannot be found that accepts argument 'x'.At line:1 char:21+ c:\src\ps\params.ps1 <<<< --my-param1 "x" + categoryInfo : InvalIDArgument: (:) [params.ps1],ParameterBindingException + FullyQualifIEdErrorID : positionalParameterNotFound,params.ps1
另一方面,使用别名my-param让我用-my-param调用脚本.
有没有一种方法可以使用前导Powershell指定参数名称?
[Management.automation.PSParser]::Tokenize( 'Command -parameter',[ref]$null)
…和…
[Management.automation.PSParser]::Tokenize( 'Command --parameter',[ref]$null)
正如您所见,解析器将前者视为参数,后者 – 作为参数.因此,唯一的方法是“内部”解析所有参数并猜测什么是参数(从您的角度来看),以及什么是参数.
总结以上是内存溢出为你收集整理的如何在PowerShell脚本中提供Linux样式的参数名称全部内容,希望文章能够帮你解决如何在PowerShell脚本中提供Linux样式的参数名称所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)