DosTips.com

A Forum all about DOS Batch
It is currently 27 May 2016 06:14

All times are UTC-06:00




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
 Post subject: %%~$ Fails in For
PostPosted: 11 Dec 2012 22:11 
Offline

Joined: 20 Aug 2010 13:57
Posts: 424
Location: Chile
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"
%~$
%~$


Top
   
 Post subject: Re: %%~$ Fails in For
PostPosted: 12 Dec 2012 00:09 
Offline
Expert

Joined: 13 Jan 2012 21:24
Posts: 469
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.


Top
   
 Post subject: Re: %%~$ Fails in For
PostPosted: 12 Dec 2012 07:24 
Offline
Expert

Joined: 12 Feb 2011 21:02
Posts: 1638
Location: United States (east coast)
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


Top
   
 Post subject: Re: %%~$ Fails in For
PostPosted: 12 Dec 2012 08:32 
Offline
Expert

Joined: 16 May 2011 08:21
Posts: 1432
Location: Flanders(Belgium)
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...


Top
   
 Post subject: Re: %%~$ Fails in For
PostPosted: 12 Dec 2012 09:19 
Offline
Expert

Joined: 12 Feb 2011 21:02
Posts: 1638
Location: United States (east coast)
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.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 5 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Yahoo [Bot] and 9 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® Forum Software © phpBB Limited