Powershell 中的比較運算符
-eq :等于
-ne :不等于
-gt :大于
-ge :大于等于
-lt :小于
-le :小于等于
-contains :包含
-notcontains :不包含
進行比較
可以將比較表達式直接輸入進Powershell控制臺,然后回車,會自動比較并把比較結果返回。
復制代碼 代碼如下:
PS C:Powershell> (3,4,5 ) -contains 2
False
PS C:Powershell> (3,4,5 ) -contains 5
True
PS C:Powershell> (3,4,5 ) -notcontains 6
True
PS C:Powershell> 2 -eq 10
False
PS C:Powershell> "A" -eq "a"
True
PS C:Powershell> "A" -ieq "a"
True
PS C:Powershell> "A" -ceq "a"
False
PS C:Powershell> 1gb -lt 1gb+1
True
PS C:Powershell> 1gb -lt 1gb-1
False
求反
求反運算符為-not 但是像高級語言一樣”! “ 也支持求反。
復制代碼 代碼如下:
PS C:Powershell> $a= 2 -eq 3
PS C:Powershell> $a
False
PS C:Powershell> -not $a
True
PS C:Powershell> !($a)
True
布爾運算
-and :和
-or :或
-xor :異或
-not :逆
復制代碼 代碼如下:
PS C:Powershell> $true -and $true
True
PS C:Powershell> $true -and $false
False
PS C:Powershell> $true -or $true
True
PS C:Powershell> $true -or $false
True
PS C:Powershell> $true -xor $false
True
PS C:Powershell> $true -xor $true
False
PS C:Powershell> -not $true
False
比較數組和集合
過濾數組中的元素
復制代碼 代碼如下:
PS C:Powershell> 1,2,3,4,3,2,1 -eq 3
3
3
PS C:Powershell> 1,2,3,4,3,2,1 -ne 3
1
2
4
2
1
驗證一個數組是否存在特定元素
復制代碼 代碼如下:
PS C:Powershell> $help=(man ls)
PS C:Powershell> 1,9,4,5 -contains 9
True
PS C:Powershell> 1,9,4,5 -contains 10
False
PS C:Powershell> 1,9,4,5 -notcontains 10
True
一、值比較
1) -eq: 相等(equal)運算符
2)
主站蜘蛛池模板:
庄浪县|
东城区|
海宁市|
松溪县|
正蓝旗|
萍乡市|
厦门市|
东海县|
沽源县|
富裕县|
宝鸡市|
福清市|
德惠市|
遵义县|
宁津县|
米脂县|
三河市|
双辽市|
陆良县|
元朗区|
虹口区|
罗源县|
陈巴尔虎旗|
平舆县|
隆回县|
安福县|
崇仁县|
依兰县|
信丰县|
沧州市|
蓬溪县|
微山县|
马公市|
庐江县|
吐鲁番市|
苗栗县|
芜湖县|
安顺市|
封丘县|
施秉县|
竹溪县|