Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 相当于BASH(etc)和#x27;类型';指挥部?_Windows_Shell_Powershell_Powershell 2.0_Command Line Interface - Fatal编程技术网

Windows 相当于BASH(etc)和#x27;类型';指挥部?

Windows 相当于BASH(etc)和#x27;类型';指挥部?,windows,shell,powershell,powershell-2.0,command-line-interface,Windows,Shell,Powershell,Powershell 2.0,Command Line Interface,在*nix上,使用BASH(etc)可以通过使用内置的“type”shell询问系统命令的位置(etc),如下所示: $ type cat cat is /bin/cat Microsoft PowerShell 2.0中是否有此“type”命令的等效项?等效项是Get命令 PS C:\> Get-Command ls CommandType Name Definition ----------- ---- ---------- Alias

在*nix上,使用BASH(etc)可以通过使用内置的“type”shell询问系统命令的位置(etc),如下所示:

$ type cat
cat is /bin/cat

Microsoft PowerShell 2.0中是否有此“type”命令的等效项?

等效项是
Get命令

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命令的行为似乎已经改变了。要包含所有结果(以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
如注释中所述,这不包括先前行为的
定义
列。我无法确定添加定义列的命令行参数,但正如@voutasaurus在下面的注释中所指出的,可以使用:

PS C:\> (Get-Command -All ls).Definition
Get-ChildItem
C:\Program Files (x86)\Git\usr\bin\ls.exe
供参考的版本信息(我没有与原始答案文本关联的版本信息,但我猜是Windows 7):


因为您用Shell标记了它,除了PowerShell的
Get命令
,还有
where.exe

PS C:\> where.exe notepad
C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe
该命令仅通过以下路径查找具有指定名称的文件:

PS C:\> where.exe readme.*
C:\Python31\README.txt
C:\Program Files (x86)\wget\README
C:\Program Files (x86)\SysinternalsSuite\readme.txt

请注意,从PowerShell调用此命令时,必须将其称为
where.exe
,因为
where Object
别名为
where

Get命令有一个-ShowCommandInfo参数来执行此操作。它还适用于$profile中定义的函数:

PS C:\Users\vp937ll> Get-Command l -ShowCommandInfo

Name          : l
ModuleName    :
Module        : @{Name=}
CommandType   : Function
Definition    : Get-ChildItem | Sort-Object -Property LastWriteTime -Descending
ParameterSets : {@{Name=__AllParameterSets; IsDefault=False; Parameters=System.Management.Automation.PSObject[]}}

这不适用于$profile中定义的函数,而type在bash中返回函数的定义。我得到的是:>Get-Command-Get-Command-Command-type-Name-Version-Source-------------Cmdlet-Get-Command3.0.0.0 Microsoft.PowerShell.Core如果您使用(Get Command Get Command)。定义,那么您实际上就得到了定义。谢谢@voutasaurus,自发布答案以来,它一定发生了更改。我已经用你的建议修改了答案。那是正确的答案
PS C:\Users\vp937ll> Get-Command l -ShowCommandInfo

Name          : l
ModuleName    :
Module        : @{Name=}
CommandType   : Function
Definition    : Get-ChildItem | Sort-Object -Property LastWriteTime -Descending
ParameterSets : {@{Name=__AllParameterSets; IsDefault=False; Parameters=System.Management.Automation.PSObject[]}}