Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is a question regarding CMD shell script, I have seen a script as below:

FOR %%X in (java.exe javac.exe ant.bat android.bat) do (

Can any one explain to me what is %%~$PATH:X ?

share|improve this question
up vote 3 down vote accepted

%%~$PATH:X is path concatenation.

%%X is the name of the instance variable, which is set to java.exe, javac.exe, etc. as it iterates through the FOR loop

The ~$PATH: between %% and X is basically searching for a file named java.exe (or whatever %%X is set to at the moment) in every directory contained within the %PATH% environment variable.

Also, see this StackOverflow question which reiterates the technique and contains some discussion about it (but doesn't explain in theoretical terms what it syntactically does). There's a good discussion about PATHEXT there, too.

share|improve this answer
Can you elaborate a bit on how exactly %%~$PATH:X works? I know how %PATH:windows=win% (substitution) and %PATH:~0,20% (substring extraction) for example work, but what is FOUND being set to here? I see that it is checking whether FOUND is DEFINED or not, not whether it EXISTs or not, so what's really happening? – Karan Nov 21 '12 at 0:18

Each directory in PATH environment variable is scanned for existence of file %X, and the name of the first matching directory is saved into FOUND.

Type HELP FOR in the windows CMD shell to get full docs.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.