powershell - bash 上相当于 `which` 的 cmd/powershell 是什么?

标签 powershell cmd

我想了解 CMD shell 使用哪个版本的可执行文件。在任何 Unix shell 中,我都会使用 which找到它。

Windows shell 中是否有等效的命令?

最佳答案

各种。

  1. 其中 是直接等效项:

    C:\Users\Joey>where cmd
    C:\Windows\System32\cmd.exe
    

    请注意,在 PowerShell 中 where 本身是 Where-Object 的别名,因此您需要在 PowerShell 中使用 where.exe

  2. cmd 中,您还可以使用 for:

    C:\Users\Joey>for %x in (powershell.exe) do @echo %~$PATH:x
    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    
  3. 在 PowerShell 中,您有 Get-Command 及其别名 gcm,如果您传递参数,它会执行相同的操作(但也适用于别名、cmdlet 和函数)在 PowerShell 中):

    PS C:\Users\Joey> Get-Command where
    
    CommandType     Name          Definition
    -----------     ----          ----------
    Alias           where         Where-Object
    Application     where.exe     C:\Windows\system32\where.exe
    

    第一个返回的命令是要执行的命令。

关于powershell - bash 上相当于 `which` 的 cmd/powershell 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11009598/

相关文章:

vba - 使用Excel宏执行命令并关闭cmd窗口

powershell - PowerShell压缩消息字符串输出

powershell - 如何更改我键入的字符串值的颜色?

cmd - 命令提示符下的发送键

batch-file - 使用 youtube-dl 下载视频并使用 FFmpeg 转换的批处理脚本

c++ - 如何在 Windows 命令行中读取输入 .in 文件

Windows 命令解释器 : how to obtain exit code of first piped command

Powershell "special"开关参数

azure - Powershell Send-MailMessage 在 Azure Pipeline 上无法进行身份验证

Azure虚拟机: Update Microsoft ODBC Driver via Powershell