What exactly is “exit” in PowerShell?

前端 未结 1 1943
余生分开走
余生分开走 2020-12-23 14:11

You can exit PowerShell by typing exit. So far so good. But what exactly is this?

PS Home:\\> gcm exit
Get-Command : The term \'exit\' is not         


        
相关标签:
1条回答
  • 2020-12-23 14:55

    It's a reserved keyword (like return, filter, function, break).

    Reference

    Also, as per Section 7.6.4 of Bruce Payette's Powershell in Action:

    But what happens when you want a script to exit from within a function defined in that script? ... To make this easier, Powershell has the exit keyword.

    Of course, as other have pointed out, it's not hard to do what you want by wrapping exit in a function:

    PS C:\> function ex{exit}
    PS C:\> new-alias ^D ex
    
    0 讨论(0)
提交回复
热议问题