$_ 在 PowerShell 中是什么意思? [英] What does $_ mean in PowerShell?
本文介绍了$_ 在 PowerShell 中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 PowerShell 中看到了很多以下内容,但它到底做了什么?
I've seen the following a lot in PowerShell, but what does it do exactly?
$_
推荐答案
这是管道中当前值的变量,在 Powershell 3 和更新版本中称为 $PSItem
.
This is the variable for the current value in the pipe line, which is called $PSItem
in Powershell 3 and newer.
1,2,3 | %{ write-host $_ }
或
1,2,3 | %{ write-host $PSItem }
例如,在上面的代码中,%{}
块会为数组中的每个值调用.$_
或 $PSItem
变量将包含当前值.
For example in the above code the %{}
block is called for every value in the array. The $_
or $PSItem
variable will contain the current value.
这篇关于$_ 在 PowerShell 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文