Qu'est-ce que "exit" dans PowerShell?

vous pouvez quitter PowerShell en tapant exit . So far So good. Mais qu'est-ce?

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

donc ce n'est pas un cmdlet, une fonction, un script ou un programme. Il laisse la question ce que exactement il est.

cela signifie malheureusement aussi qu'on ne peut pas créer d'Alias pour 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

y a-t-il d'autres commandes qui ne sont pas des commandes?

ETA: juste pour référence: je sais que je peux simplement l'envelopper dans une fonction. Mon profil a les lignes

# exit with Ctrl+D
iex "function $([char]4) { exit }"

dedans. Ma question était juste de savoir ce qu'est exactement cette commande est.

53
demandé sur Peter Mortensen 2009-08-14 02:54:26

1 réponses

c'est un mot-clé réservé (comme retour, filtre, fonction, pause).

référence

Aussi, conformément à la Section 7.6.4 de Bruce Payette Powershell en Action :

mais que se passe-t-il quand vous voulez qu'un script sorte d'une fonction définie dans ce script? ... pour faciliter cela, Powershell a la sortie mot-clé .

bien sûr, comme d'autres l'ont fait remarquer, il n'est pas difficile de faire ce que vous voulez en enveloppant exit dans une fonction:

PS C:\> function ex{exit}
PS C:\> new-alias ^D ex
75
répondu zdan 2011-10-09 04:15:32