Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
101 views
in Technique[技术] by (71.8m points)

Whats the cmd/powershell equivalent of `which` on bash?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Various.

  1. where is a direct equivalent:

    C:UsersJoey>where cmd
    C:WindowsSystem32cmd.exe
    

    Note that in PowerShell where itself is an alias for Where-Object, thus you need to use where.exe in PowerShell.

  2. In cmd you can also use for:

    C:UsersJoey>for %x in (powershell.exe) do @echo %~$PATH:x
    C:WindowsSystem32WindowsPowerShellv1.0powershell.exe
    
  3. In PowerShell you have Get-Command and its alias gcm which does the same if you pass an argument (but also works for aliases, cmdlets and functions in PowerShell):

    PS C:UsersJoey> Get-Command where
    
    CommandType     Name          Definition
    -----------     ----          ----------
    Alias           where         Where-Object
    Application     where.exe     C:Windowssystem32where.exe
    

    The first returned command is the one that would be executed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...