PowerShell入门教程之PowerShell和Cmd命令行的关系?

2019-09-30 13:40:14王振洲

Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.

PS D:ProjectsPractisePowerShell> get-help

TOPIC
    Windows PowerShell Help System

Cmd也可以在PowerShell中作为应用程序运行,其运行方式与在Cmd中运行PowerShell相似:

PS D:ProjectsPractisePowerShell> cmd
Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

D:ProjectsPractisePowerShell>dir /ad
Volume in drive D is Doc
Volume Serial Number is A6C5-E7CE

Directory of D:ProjectsPractisePowerShell

01/30/2013  04:54 PM    <DIR>          .
01/30/2013  04:54 PM    <DIR>          ..
01/23/2013  12:35 PM    <DIR>          d1
01/23/2013  12:35 PM    <DIR>          d2

PowerShell通过Alias这个特性,可以让使用者以Cmd风格来使用PowerShell命令。这样做的好处是让用户在刚接触PowerShell的时候,就像在使用Cmd一样亲切、熟悉。坏处是,让人容易把PowerShell和Cmd搞混了。不过当你了解了Alias的概念和Get-Alias命令以后,这个问题将迎刃而解:

PS D:ProjectsPractisePowerShell> get-alias dir, echo, type

CommandType     Name                                               ModuleName
-----------     ----                                               ----------
Alias           dir -> Get-ChildItem

Alias           cd -> Set-Location
Alias           echo -> Write-Output

就是说dir实际上是PowerShell的Get-ChildItem命令的一个别名,cd是Set-Location的别名。。。到这里PowerShell和Cmd的关系问题算是解决了。

Cmd命令行会被PowerShell替代吗?

  我其实一直以来都很讨厌类似“谁不如谁好”、“谁要代替谁”的问题,放到这里也一样,新的东西必然有它的优越性,旧的东西也有一票粉丝。从现在PowerShell被接受的程度来看,短时间内Cmd不会被PowerShell替代。长远来看呢,谁知道呢。我只知道,多一份选择就多一份自由,多一种可能性。