在 *nix 上,使用 BASH(等)你通过使用内置的“type”shell 询问系统命令所在的位置(等),如下所示:
$ type cat
cat is /bin/cat
Microsoft PowerShell 2.0 中是否有与此“type”命令等效的命令?
最佳答案
一个等价物是 Get-Command
。
PS C:\> Get-Command ls
CommandType Name Definition
----------- ---- ----------
Alias ls Get-ChildItem
Application ls.exe D:\usr\local\wbin\ls.exe
Application ls.exe C:\Program Files (x86)\Git\bin\ls.exe
Windows 10 更新:
自从我发布了这个答案后,Get-Command
的行为似乎发生了变化。要包含所有结果(以 Un*x 的样式 type
),现在我需要传递 -All
标志,如下所示:
PS C:\> Get-Command -All ls
CommandType Name Version Source
----------- ---- ------- ------
Alias ls -> Get-ChildItem
Application ls.exe 0.0.0.0 C:\Program Files (x86)\Git\usr\bin\ls.exe
如评论中所述,此不像以前的行为一样包含Definition
列。我无法确定添加定义列的命令行参数,但正如@voutasaurus 在下面的评论中指出的那样,可以使用:
PS C:\> (Get-Command -All ls).Definition
Get-ChildItem
C:\Program Files (x86)\Git\usr\bin\ls.exe
供引用的版本信息(我没有原始答案文本相关的版本信息,但我猜它是Windows 7):
PS C:\> [System.Environment]::OSVersion.Version
Major Minor Build Revision
----- ----- ----- --------
10 0 15063 0
关于windows - 相当于 BASH(等) 'type' 命令的 PowerShell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12320682/