Page 1 of 1
%%~$ Fails in For
Posted: 11 Dec 2012 22:11
by carlos
Hello.
Maybe this have mentioned before. But anyways I post this:
In For command if you use the character $, it will fail if you want remove the quotes, using:
Example:
Code: Select all
@Echo Off
Rem Works:
For /F %%$ in ("Hi") do echo(%%$
For %%$ in ("Hi") do echo(%%$
Rem Fails:
For /F %%$ in ("Hi") do echo(%%~$
For %%$ in ("Hi") do echo(%%~$
Pause
Print:
Re: %%~$ Fails in For
Posted: 12 Dec 2012 00:09
by Liviu
carlos wrote:In For command if you use the character $, it will fail if you want remove the quotes, using %%~$
That's dangerously close to the "%%~$PATH:I" syntax, and the parser mistakes it for such. Try "echo(%%~$:" for verification, which outputs nothing at all.
Re: %%~$ Fails in For
Posted: 12 Dec 2012 07:24
by dbenham
Interesting Carlos.
I never thought to test that before, but I suppose it makes some amount of sense. The parser is getting confused by the
%~$PATH:I modifier.
FOR /? wrote:Code: Select all
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string
I posted an analysis of
valid characters for use as FOR variables on StatckOverflow - see the Addendum. I've updated that answer with the info about
%%~$. I gave you a credit in a comment after the answer.
Somewhere on DosTips I started a discussion thread about FOR variables, but I can't find it
Dave Benham
Re: %%~$ Fails in For
Posted: 12 Dec 2012 08:32
by Ed Dyreen
dbenham wrote:Interesting Carlos.
...
I gave you a credit in a comment after the answer.
But this is nothing new, jeb posted about this long time ago, it was
explained numerous times.
I took a quick look at your Addendum, the exclamation mark isn't listed. Don't advice people to use it, but for completeness, maybe...
Re: %%~$ Fails in For
Posted: 12 Dec 2012 09:19
by dbenham
Ed Dyreen wrote:I took a quick look at your Addendum, the exclamation mark isn't listed. Don't advice people to use it, but for completeness, maybe...
What is special about
%%! My addendum isn't an attempt to list all possible FOR variable characters. Rather it is an attempt to list characters that are problematic or require special syntax.