[英]Getting the last executed command as output without using up arrow - PowerShell
I'm looking for a command to get the last executed command as output.我正在寻找一个命令来获取最后执行的命令为 output。 So far I found the automatic variable
$$
, but it gives only the last word of the last executed command.到目前为止,我找到了自动变量
$$
,但它只给出了最后一个执行命令的最后一个字。 I'd like to avoid to use the up arrow of the keyboard (I need a command, not a key).我想避免使用键盘的向上箭头(我需要一个命令,而不是一个键)。
If the last command was part of your current session (vs. the last command at the end of your previous session), you can use the Get-History
cmdlet:如果最后一个命令是当前 session 的一部分(与上一个会话结束时的最后一个命令相比),则可以使用
Get-History
cmdlet:
Get-History -Count 1
To get just the text of the command, you can pipe it through Select-Object
:要获取命令的文本,您可以通过
Select-Object
pipe 它:
Get-History -Count 1 | Select-Object -ExpandProperty CommandLine
Get-History | select -last 1 | select -expand commandline
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.