这个问题在这里已经有了答案:
Pass object[] into a function in PowerShell
(1 个回答)
4年前关闭。
我试图创建一个哈希表,
$input = @{'G'=100;'E'=50;'D'=35;'A'=100}
并且无法弄清楚为什么它不会像往常一样使用
write-host
之类的命令显示。 ,或简单地 $input
. write-host
返回 System.Collections.ArrayList+ArrayListEnumeratorSimple
. $input
什么也没回。没有抛出错误。凭直觉,我重命名了哈希表,然后繁荣,它看起来很正常。在 ISE 中打开一个新的 powershell 选项卡,我观察到变量
$input
即使我没有在这种环境中定义它,也充满了智能感知。现在我很好奇:这个系统变量 $input 有什么用?我在第 4 版。
最佳答案
$INPUT
Contains an enumerator that enumerates all input that is passed to a function. The
$input
variable is available only to functions and script blocks (which are unnamed functions). In the Process block of a function, the$input
variable enumerates the object that is currently in the pipeline. When the Process block completes, there are no objects left in the pipeline, so the$input
variable enumerates an empty collection. If the function does not have a Process block, then in the End block, the$input
variable enumerates the collection of all input to the function.
这在 PowerShell 中也可用:
Get-Help about_Automatic_Variables
I also have an open feature request for
Set-StrictMode
to handle detection of this .
关于powershell - 在 Powershell 中,$input 是做什么用的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43241124/