View unanswered posts | View active topics It is currently 17 Sep 2014 17:37



Post new topic Reply to topic  [ 5 posts ] 
%%~$ Fails in For 
Author Message

Joined: 20 Aug 2010 13:57
Posts: 369
Location: Chile
Post %%~$ Fails in For
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:
Code:
%%~$


Example:
Code:
@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:
Code:
Hi
"Hi"
%~$
%~$


11 Dec 2012 22:11
Profile WWW
Expert

Joined: 13 Jan 2012 21:24
Posts: 440
Post Re: %%~$ Fails in For
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.


12 Dec 2012 00:09
Profile
Expert

Joined: 12 Feb 2011 21:02
Posts: 1211
Location: United States (east coast)
Post Re: %%~$ Fails in For
Interesting Carlos. :D

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:
    %~$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


12 Dec 2012 07:24
Profile
Expert

Joined: 16 May 2011 08:21
Posts: 1261
Location: Flanders_(Belgium)
Post Re: %%~$ Fails in For
dbenham wrote:
Interesting Carlos. :D
...
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...


12 Dec 2012 08:32
Profile WWW
Expert

Joined: 12 Feb 2011 21:02
Posts: 1211
Location: United States (east coast)
Post Re: %%~$ Fails in For
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.


12 Dec 2012 09:19
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.