【发布时间】:2016-05-17 14:29:14
【问题描述】:
在 PowerShell 中,我想比较对象并在它们匹配时返回 true。最后,管道应该只返回一个布尔值 - 如果每个管道元素返回 true,则返回 true,否则返回 false。仅使用管道如何实现此目的?
例子:
@("a","b","c") | % { $_ -match "[a-z]" } # -> should only return true once
@("a","1","c") | % { $_ -match "[a-z]" } # -> should only return false once
【问题讨论】:
-
您也可以为此使用
-notcontains:(@("a","b","c") | % { $_ -match "[a-z]" }) -notcontains $false返回True。不过,这并没有使用管道。
标签: powershell