您可以通过键入exit
退出PowerShell。到目前一切尚好。但这到底是什么呢?
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 }"
在他们身上。我的问题只是想知道这个命令到底是什么。
发布于 2009-08-13 23:33:37
它是一个保留的关键字(如return、filter、function、break)。
此外,根据Bruce Payette的Powershell in Action的7.6.4节
但是,如果您想要从脚本中定义的函数中退出脚本,会发生什么呢?...为了简化这一过程,Powershell提供了关键字。
当然,正如其他人所指出的那样,通过将exit包装在函数中并不难:
PS C:\> function ex{exit}
PS C:\> new-alias ^D ex
https://stackoverflow.com/questions/1275090
复制相似问题