Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

sh/bat hybrid that checks available commands. Despite its hackish look, it was tested under Windows XP, wine, ksh, zsh, dash and bash.

View exists.cmd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
: ::\
@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
Something went wrong with that request. Please try again.