您可以通过键入退出PowerShell exit
。到现在为止还挺好。但这到底是什么?
PS Home:\> gcm exit
Get-Command : The term 'exit' is not recognized as the name of a cmdlet, function, script file, or operable program. Ch
eck the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:4
+ gcm <<<< exit
+ CategoryInfo : ObjectNotFound: (exit:String) [Get-Command], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
因此,它既不是cmdlet,函数,脚本或程序。剩下的问题是它到底是什么。
不幸的是,这也意味着无法创建别名exit
:
PS Home:\> New-Alias ^D exit
PS Home:\> ^D
Cannot resolve alias '♦' because it refers to term 'exit', which is not recognized as a cmdlet, function, operable prog
ram, or script file. Verify the term and try again.
At line:1 char:2
+ ♦ <<<<
+ CategoryInfo : ObjectNotFound: (♦:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : AliasNotResolvedException
还有没有这种命令的命令吗?
ETA:仅供参考:我知道我可以将其包装为一个函数。我的个人资料已上线
# exit with Ctrl+D
iex "function $([char]4) { exit }"
在他们之中。我的问题只是想知道此命令的确切含义。
Get-Help Exit-PSSession
您还可以使用Exit关键字结束交互式会话。效果与使用Exit-PSSession相同。因此它也说Exit
是一个关键字。但是,似乎引号不能被认为是暗示,Exit
并且Exit-PSSession
在所有情况下都是等效的。exit关键字可以与可以转换为的参数一起使用[int]
,在这种情况下,该数字将是退出代码。例如Exit 42
。