首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在PowerShell中"exit“到底是什么?

在PowerShell中"exit“到底是什么?
EN

Stack Overflow用户
提问于 2009-08-13 22:54:27
回答 1查看 176.2K关注 0票数 78

您可以通过键入exit退出PowerShell。到目前一切尚好。但这到底是什么呢?

代码语言:javascript
复制
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的别名

代码语言:javascript
复制
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:仅供参考:我知道我可以简单地将其封装到一个函数中。我的个人资料里有这样的台词

代码语言:javascript
复制
# exit with Ctrl+D
iex "function $([char]4) { exit }"

在他们身上。我的问题只是想知道这个命令到底是什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-08-13 23:33:37

它是一个保留的关键字(如return、filter、function、break)。

Reference

此外,根据Bruce Payette的Powershell in Action的7.6.4节

但是,如果您想要从脚本中定义的函数中退出脚本,会发生什么呢?...为了简化这一过程,Powershell提供了关键字

当然,正如其他人所指出的那样,通过将exit包装在函数中并不难:

代码语言:javascript
复制
PS C:\> function ex{exit}
PS C:\> new-alias ^D ex
票数 120
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1275090

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档