MS Dos is pretty simple shell implementation, and as I have figured out that interpretation of one DOS command line goes in 2 phases:
- evaluation of variables in current line
- interpretation of evaluated command line
In this case your command line:
IF "%~$PATH:1" == "" (
echo %1 is not found in any directories from PATH env-var.
) ELSE (
echo %1 is found: %~$PATH:1
)
would be interpreted as:
IF "O:\temp\pfiles (x86)\mystuff.txt" == "" (
echo mystuff is not found in any directories from PATH env-var.
) ELSE (
echo mystuff.txt is found: O:\temp\pfiles (x86)\mystuff.txt
)
Now we can notice the problem in (x86)
, i.e. interpreter sees this somehow like this - first )
closes else statement:
) ELSE (
echo mystuff.txt is found: O:\temp\pfiles (x86
)\mystuff.txt
)
Solution: put "" around all potentially problematic variables.
I usually put quotes around the whole echo command content, for example:
echo "%1 is found: %~$PATH:1"