What does $_ mean in PowerShell?

后端 未结 6 887
孤城傲影
孤城傲影 2020-12-02 04:07

I\'ve seen the following a lot in PowerShell, but what does it do exactly?

$_
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 05:07

    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 $_ } 
    

    or

    1,2,3 | %{ write-host $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.

提交回复
热议问题