Equivalent of *Nix 'which' command in PowerShell?

后端 未结 14 2250
刺人心
刺人心 2020-11-28 00:16

How do I ask PowerShell where something is?

For instance, \"which notepad\" and it returns the directory where the notepad.exe is run from according to the current

14条回答
  •  天涯浪人
    2020-11-28 01:08

    If you want a comamnd that both accepts input from pipeline or as paramater, you should try this:

    function which($name) {
        if ($name) { $input = $name }
        Get-Command $input | Select-Object -ExpandProperty Path
    }
    

    copy-paste the command to your profile (notepad $profile).

    Examples:

    ❯ echo clang.exe | which
    C:\Program Files\LLVM\bin\clang.exe
    
    ❯ which clang.exe
    C:\Program Files\LLVM\bin\clang.exe
    

提交回复
热议问题