${$} 在 PowerShell 中是什么意思/做什么?

All*_*nde 8 powershell powershell-5.0

在学习 PowerShell 时,我${$}错误地执行了命令并得到如下输出:

PS C:\Users\myuser> Get-ChildItem Env: | Out-File -FilePath $home\env.txt
PS C:\Users\myuser> ${$}
$home\env.txt
Run Code Online (Sandbox Code Playgroud)

首先,我认为它类似于$_,但这样${$_}做的行为并不相同。

根据我尝试过的其他示例,它似乎从上一个命令中检索了最后一个参数,但我不太确定它是如何工作的或它实际在做什么。

我希望得到解释或指向文档/解释的链接。

PowerShell 主机信息(如果需要):

名称:ConsoleHost
版本:5.1.17134.858
InstanceId:[删除,因为我不小心,如果可以不小心共享]
UI:System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture:en-US
CurrentUICulture:en-US
PrivateData:Microsoft。 PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace

小智 9

输入${$}被评估为自动变量$$$$本身被设置为会话中最后一个输入行的最后一个标记。在您的情况下,它被设置为最后一个参数home\env.txt

您也可以通过类似${?}这样的输入看到这种效果,结果是$?另一个自动变量,其中包含上次执行命令的结果。

有关自动变量的列表,请参阅:https : //docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables