Powershell - 括号
Powershell 支持三种类型的括号。
小括号(圆括号) −()
大括号 −{}
方括号 −[]
小括号(圆括号)
这种类型的括号用于
传递参数
附上多组指令
消除歧义
创建数组
示例
> $array = @("item1", "item2", "item3")
> foreach ($element in $array) { $element }
item1
item2
item3
大括号
这种类型的括号用于
附加语句
块命令
示例
$x = 10
if($x -le 20){
write-host("This is if statement")
}
这将产生以下结果 −
输出
This is if statement.
方括号
这种类型的括号用于
访问数组
访问哈希表
使用正则表达式过滤
示例
> $array = @("item1", "item2", "item3")
> for($i = 0; $i -lt $array.length; $i++){ $array[$i] }
item1
item2
item3
>Get-Process [r-s]*
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
320 72 27300 33764 227 3.95 4028 SCNotification
2298 77 57792 48712 308 2884 SearchIndexer
...

