国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PowerShell > 正文

Windows Powershell條件表達(dá)式之條件操作符

2020-05-30 20:16:55
字體:
供稿:網(wǎng)友

Powershell 中的比較運(yùn)算符
-eq :等于
-ne :不等于
-gt :大于
-ge :大于等于
-lt :小于
-le :小于等于
-contains :包含
-notcontains :不包含

進(jìn)行比較

可以將比較表達(dá)式直接輸入進(jìn)Powershell控制臺(tái),然后回車,會(huì)自動(dòng)比較并把比較結(jié)果返回。

代碼如下:
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

求反

求反運(yùn)算符為-not 但是像高級(jí)語言一樣”! “ 也支持求反。

代碼如下:
PS C:Powershell> $a= 2 -eq 3
PS C:Powershell> $a
False
PS C:Powershell> -not $a
True
PS C:Powershell> !($a)
True

布爾運(yùn)算

-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

比較數(shù)組和集合

過濾數(shù)組中的元素

代碼如下:
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

驗(yàn)證一個(gè)數(shù)組是否存在特定元素

代碼如下:
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)運(yùn)算符
2) –ne:不相等(not-equal)運(yùn)算符
3) –lt: 小于(less-than)
4) –gt: 大于(greater than)
5) le: 小于等于 (less-than-or-equal)
6) ge: 大于等于(greater-than-or-equal)
值比較運(yùn)算符可以用來比較兩個(gè)數(shù)字,也可以用來比較兩個(gè)字符串。
注意:字符串比較時(shí)忽略大小寫,如果需要大小寫敏感比較,可以使用操作符-ceq, -clt, -cle, -cge。大小寫敏感比較時(shí),小寫字母小于大寫字母。
在PowerShell中明確的大小寫不敏感比較操作符是在默認(rèn)操作符前加前綴i,即-ieq,-ilt,-ile,-igt,-ige。

二、隱式類型轉(zhuǎn)換

在PowerShell中自動(dòng)轉(zhuǎn)換的通常規(guī)則是對(duì)于兩個(gè)不同類型變量組成的表達(dá)式,自動(dòng)將右側(cè)的變量轉(zhuǎn)換為左側(cè)變量的類型,之后計(jì)算表達(dá)式的值。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大厂| 镇坪县| 平塘县| 惠来县| 科技| 萍乡市| 勃利县| 体育| 容城县| 固镇县| 西平县| 定州市| 同德县| 南漳县| 涞源县| 岗巴县| 新巴尔虎左旗| 惠州市| 苍溪县| 舒城县| 昭苏县| 儋州市| 江源县| 祁阳县| 景洪市| 兴安盟| 利川市| 清新县| 阿图什市| 福州市| 防城港市| 德阳市| 海口市| 五台县| 肇东市| 封丘县| 德格县| 奈曼旗| 浦城县| 中山市| 泰安市|