For those unaware of this command, which perl, would simply find the first perl in the PATH. In that sense it is also a nice tool to see if a command you need is actually available.
As usual Google lend me a hand and showed me this:
Code: Select all
@echo off
rem --------------------------------------------------------
rem File: which.cmd
rem Description: Windows equivalent of Unix which command
rem Author: Pankaj Kumar
rem Copyright 2004 Pankaj Kumar. All Rights Reserved.
rem License: This software is available under GPL (http://www.gnu.org/licenses/gpl.html)
rem ---------------------------------------------------------
setlocal
if "%1" == "" goto noArg
set fullpath=%~$PATH:1
if "%fullpath%" == "" goto notFound
echo Found in PATH: %fullpath%
goto end
:noArg
echo No Argument specified
goto end
:notFound
echo Argument "%1" not found in PATH
:end
endlocal
While this works OK when I know if I'm looking for a .exe or a .com file, I would like this batch to use the PATHEXT variable so that I only need to specify the name of the executable and not its extension.
I guess I can chop PATHEXT into pieces using something like this:
Code: Select all
FOR /F "delims=;" a%% in ("%PATHEXT%") do call:a_function %%a
But before I can work on that, I need to understand what this here actually does:
Code: Select all
set fullpath=%~$PATH:1
And now I just realised I don't understand how the set command works
So my "perl.exe" is inside %1, and then suddenly fullpath becomes c:\perl\bin\perl.exe
I really like to understand how this works.