Is there an equivalent of 'which' on the Windows command line?

后端 未结 26 2052
悲哀的现实
悲哀的现实 2020-11-22 00:40

As I sometimes have path problems, where one of my own cmd scripts is hidden (shadowed) by another program (earlier on the path), I would like to be able to find the full pa

26条回答
  •  -上瘾入骨i
    2020-11-22 01:06

    Just have to post this Windows' one liner batch file:

    C:>type wh.cmd
    @for %%f in (%*) do for %%e in (%PATHEXT% .dll .lnk) do for %%b in (%%f%%e) do for %%d in (%PATH%) do if exist %%d\%%b echo %%d\%%b
    

    A test:

    C:>wh ssh
    C:\cygwin64\bin\ssh.EXE
    C:\Windows\System32\OpenSSH\\ssh.EXE
    

    Not quite a one-liner if you wrap the code in setlocal enableextensions and endlocal.

提交回复
热议问题