Last active
November 19, 2018 14:21
-
-
Save alganet/9531262 to your computer and use it in GitHub Desktop.
sh/bat hybrid that checks available commands. Despite its hackish look, it was tested under Windows XP, wine, ksh, zsh, dash and bash.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
: ::\ | |
@echo off | |
rem () ( command -v $1 >/dev/null 2>&1; return $? ) | |
rem : "Usage sh: $ sh exists.cmd ls && echo exists " | |
rem : "Usage bat: > exists.cmd notepad " | |
rem : " > echo %ErrorLevel% " | |
rem $1 <<REM | |
:exists | |
if exist %1 exit /b 0 | |
for %%P in ("%PATH:;=" "%") do ( | |
if exist %%~P\%1 ( exit /b 0 ) | |
call :exists_ext %%~P\%1 | |
if not errorlevel 1 ( exit /b 0 ) | |
) | |
exit /b 1 | |
:exists_ext | |
for %%P in ("%PATHEXT:;=" "%") do ( | |
if exist %1%%~P ( exit /b 0 ) | |
) | |
exit /b 1 | |
REM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment