Powershell 了解Cmdlet位置参数
好的,请原谅我,我是一个Powershell 了解Cmdlet位置参数,powershell,cmdlets,Powershell,Cmdlets,好的,请原谅我,我是一个PowerShell的新手,目前我正在读一本Windows PowerShell烹饪书试着开始学习。到目前为止,除了一件事之外,我对位置参数到Cmdlet完全感到困惑 例如:选择字符串 语法如下: Select-String [-Pattern] <String[]> [-Path] <String[]> [-AllMatches] [-CaseSensitive] [-Context <Int32[]>] [-Encoding <
PowerShell
的新手,目前我正在读一本Windows PowerShell烹饪书
试着开始学习。到目前为止,除了一件事之外,我对位置参数
到Cmdlet
完全感到困惑
例如:选择字符串
语法如下:
Select-String [-Pattern] <String[]> [-Path] <String[]> [-AllMatches] [-CaseSensitive] [-Context <Int32[]>]
[-Encoding <String>] [-Exclude <String[]>] [-Include <String[]>] [-List] [-NotMatch] [-Quiet] [-SimpleMatch]
[<CommonParameters>]
Select-String [-Pattern] <String[]> [-AllMatches] [-CaseSensitive] [-Context <Int32[]>] [-Encoding <String>]
[-Exclude <String[]>] [-Include <String[]>] [-List] [-NotMatch] [-Quiet] [-SimpleMatch] -InputObject <PSObject>
[<CommonParameters>]
Select-String [-Pattern] <String[]> [-AllMatches] [-CaseSensitive] [-Context <Int32[]>] [-Encoding <String>]
[-Exclude <String[]>] [-Include <String[]>] [-List] [-NotMatch] [-Quiet] [-SimpleMatch] -LiteralPath <String[]>
[<CommonParameters>]
基于位置参数
的概念,因为参数-模式
是第一个参数。值
可以与参数-Pattern
匹配。我能理解
但是,当我尝试此命令行时,请选择String-AllMatches。值
不在第一行。为什么选择字符串
可以知道它并计算出结果?有人能告诉我更多的信息以便更好地理解它吗?谢谢。这是第一个未命名的参数。位置值告诉cmdlet哪个参数属于哪个参数
命令选择字符串-allmatches.
将-allmatches
开关链接到其参数,并将
设置为$args
-数组(参数数组)中的第一项,因为它前面没有-parametername
然后,由于Select String
包含其参数的位置值,cmdlet知道arguments数组中的第一项($args[0]
)应绑定到-Pattern
参数
如果您想更好地理解这一点,请通过运行以下命令阅读帮助部分中有关参数位置?
的部分:
Get-Help about_Parameters
然后注意,-Pattern
参数的位置为1,如下所示:
Get-Help select-string -Parameter pattern
-Pattern <String[]>
Specifies the text to find. Type a string or regular expression. If you type a string, use the SimpleMatch parameter.
To learn about regular expressions, see about_Regular_Expressions.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
找到答案,
获取帮助选择字符串-参数*
显示参数的详细信息,-Pattern
是位置1参数。谢谢。+++1太好了!你将来会回答我所有的问题<代码>跟踪和获取帮助
谢谢!圣诞快乐!
Get-Help select-string -Parameter pattern
-Pattern <String[]>
Specifies the text to find. Type a string or regular expression. If you type a string, use the SimpleMatch parameter.
To learn about regular expressions, see about_Regular_Expressions.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
Trace-Command -Expression { "Hello World" | Select-String -allmatches . } -Name ParameterBinding -PSHost