• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Exit = last of the "built-in commands"?

L

Lucvdv

#1
Just curious: are there any other built-in commands (in the old cmd
terminology) left over besides "exit"?

Exit does what I expected it to do, quit didn't do anything, and after
finding that out I just noticed this:

PS C:\> set-alias quit exit
PS C:\> quit
Cannot resolve alias 'quit' because it refers to term 'exit', which is not
recognized as a cmdlet, function, operable program, or script file. Verify
the term and try again.
At line:1 char:4
+ quit <<<<
 

My Computer

D

dreeschkind

#2
"Lucvdv" wrote:

> Just curious: are there any other built-in commands (in the old cmd
> terminology) left over besides "exit"?


Well, PowerShell has its own scripting language (IMHO cmd.exe does not have
anything that comes close to being a language) so you could just compare
"exit" with other common language keywords like "for" "while" "switch"
"break" etc.

> Exit does what I expected it to do, quit didn't do anything, and after
> finding that out I just noticed this:
>
> PS C:\> set-alias quit exit
> PS C:\> quit
> Cannot resolve alias 'quit' because it refers to term 'exit', which is not
> recognized as a cmdlet, function, operable program, or script file. Verify
> the term and try again.
> At line:1 char:4
> + quit <<<<


Thill will work:
PS> function exit {exit}
PS> set-alias quit exit
PS> quit

or even shorter:
function quit {exit}

Btw.:
I suggested that "exit" should be a customizable function like TabExpansion
or Prompt. This would enable for example saving or cleaning up various data
automatically (e.g. exporting history) when closing PowerShell without the
need to remember to call a special function or cmdlet with another name.
You can vote for this on the Connect site if you like this idea:

https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=158962&SiteID=99

--
greetings
dreeschkind
 

My Computer

A

Alex K. Angelopoulos [MVP]

#3
"Lucvdv" <replace_name@null.net> wrote in message
news:n3k6l21p7sfs9bnk956rp2uqhkl4g8vrar@4ax.com...
> Just curious: are there any other built-in commands (in the old cmd
> terminology) left over besides "exit"?


Technically, it's not a command; it's an internal keyword used for control
flow, akin to break/continue/return/if and so on.

> Exit does what I expected it to do, quit didn't do anything, and after
> finding that out I just noticed this:
>
> PS C:\> set-alias quit exit
> PS C:\> quit
> Cannot resolve alias 'quit' because it refers to term 'exit', which is not
> recognized as a cmdlet, function, operable program, or script file. Verify
> the term and try again.
> At line:1 char:4
> + quit <<<<


You've stumbled across one of the important points about how PowerShell
interprets code. Here's another way to explain it.

PowerShell starts out in "expression" mode, attempting to match tokens to
things it understands internally: specific keywords, variables, or literal
values. If it doesn't find a match, it then goes to statement mode and tries
to treat the token as a command.

Since 'quit' is not recognized internally PS now tries to treat it as a
command, and sure enough, it's an alias for "exit". However, aliasing ONLY
works for commands! It looks for an alias,function,filter,cmdlet, or
external script or Windows native command named "exit" and doesn't find one.
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)