【发布时间】:2014-11-14 18:12:57
【问题描述】:
有时我执行了一个 PowerShell 命令,却忘记将它的返回值/对象存储在一个变量中。 PowerShell 是否将最后一个命令的返回对象存储在我可以访问的变量中?
PS C:\> Get-ChildItem
...
PS C:\> # Oh no, I forgot to assign the output to a variable
PS C:\> $a = Get-ChildItem
PS C:\>
【问题讨论】:
-
这对于交互式 PowerShell 来说是一个很棒的功能。我发现类似的 Python 交互变量
_非常有用。 “在 [Python] 交互模式下,最后打印的表达式被分配给变量 _。” 来自 Informal Introduction to Python - 搜索页面“最后打印的表达式”
标签: powershell