您可以通过键入来退出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
Run Code Online (Sandbox Code Playgroud)
所以它既不是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
Run Code Online (Sandbox Code Playgroud)
还有更多这样的命令没有命令吗?
ETA:仅供参考:我知道我可以简单地将其包装成一个函数.我的个人资料有线条
# exit with Ctrl+D
iex "function $([char]4) { exit }"
Run Code Online (Sandbox Code Playgroud)
在他们中.我的问题只是要知道这个命令到底是什么.
zda*_*dan 90
它是一个保留关键字(如return,filter,function,break).
另外,根据Bruce Payette的Powershell in Action第7.6.4节:
但是当您希望脚本从该脚本中定义的函数中退出时会发生什么?...为了使这更容易,Powershell有exit关键字.
当然,正如其他人所指出的那样,通过在函数中包含exit来做你想要的并不难:
PS C:\> function ex{exit}
PS C:\> new-alias ^D ex
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
114120 次 |
| 最近记录: |