[英]What does mean % , $_ and @ in Powershell?
这是什么意思:Powershell中的$_
和%
?
1..10 | Foreach {if($_%2){"$_ is odd number"}}
%
Foreach-Object
. Foreach-Object
的PowerShell别名。 You can execute the Get-Alias
command to see other potential aliases that may contain special characters like Where-Object
's alias ?
Get-Alias
命令来查看其他可能包含特殊字符的别名,例如Where-Object
的别名?
. $_
$PSItem
$PSItem
同义词 Foreach-Object
script block ( {}
). Foreach-Object
脚本块( {}
)中的当前对象。 Where-Object {}
script block and Select-Object
hash tables. Where-Object {}
脚本块和Select-Object
哈希表中。 @
@
character @
字符 @VariableName
. @VariableName
。 The variable can be an array or hash table. Get-Process @Params
. Get-Process @Params
。 Used for declaring and initializing arrays via the array sub-expression operator @()
. 用于通过数组子表达式运算符
@()
声明和初始化数组。
$myArray = @()
and $myArray = @("value1","value2")
. $myArray = @()
和$myArray = @("value1","value2")
。 $variable = @{}
or $variable = @{Property=Value}
. $variable = @{}
或$variable = @{Property=Value}
。 @'
or @"
and closing the string value with a corresponding '@
or "@
. @'
或@"
开头的字符串值并以相应的'@
或"@
@"
结束字符串值来表示。
Extra Reading and Notable Links: 额外阅读和著名链接:
See About Arithmetic Operators for information on modulus among other arithmetic operators. 有关其他算术运算符的模数信息,请参见关于算术运算符。
See Foreach-Object for more information about Foreach-Object
and how objects are processed. 有关Foreach
Foreach-Object
以及如何处理对象的更多信息,请参见Foreach对象 。
See About Splatting for more information and usage of splatting. 有关飞溅的更多信息和用法,请参阅关于飞溅 。
Another good resource is About Automatic Variables , which will list PowerShell's reserved/automatic variables. 另一个很好的资源是关于自动变量 ,它将列出PowerShell的保留/自动变量。 They are created and maintained by PowerShell.
它们由PowerShell创建和维护。 You will notice there are some variables that have non-alpha and non-numeric characters.
您会注意到有些变量具有非字母和非数字字符。 You should only use these variables for their intended purposes and not use their names when you create your own custom variables.
在创建自己的自定义变量时,应仅将这些变量用于其预期目的,而不应使用其名称。
See About Arrays for details on the array sub-expression operator. 有关数组子表达式运算符的详细信息,请参见关于数组 。
See About Hash Tables for details on creating and manipulating hash table objects. 有关创建和操作哈希表对象的详细信息,请参见关于哈希表 。
See About Quoting Rules to see more information and examples of using here-strings. 请参阅关于报价规则,以了解更多信息和使用此处字符串的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.