#1 16 Aug 2016 19:00

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 419

for escaping

On windows 10 this does not work:

FOR %%G IN (c:\program^ files\MyFile.txt) DO copy %%G d:\backups\

Though I'm pretty sure this worked on older versions of windows (may be Vista...)


the only way to escape spaces is to use quotes.

Same for for /d (which also can be used for iteration of items)

Offline

#2 17 Aug 2016 09:57

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,027

Re: for escaping

I don't recall ever seeing caret used for space escaping (or having it succeed myself).  Not really sure why you would when dquote works.

Just tried on Server 2008R2 and it doesn't work.  Don't have anything older to hand.


cmd | *sh | Puppet | PowerShell | AutoIT3

Offline

#3 17 Aug 2016 17:02

jeb
Member
From: Germany
Registered: 19 Nov 2010
Posts: 106

Re: for escaping

In windows 7 it fails too.

for %%A in (one^ two) do echo #%%A#

Output
#one#
#two#

Offline

#4 18 Aug 2016 09:24

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 419

Re: for escaping

bluesxman wrote:

I don't recall ever seeing caret used for space escaping (or having it succeed myself).  Not really sure why you would when dquote works.

Just tried on Server 2008R2 and it doesn't work.  Don't have anything older to hand.



I raised the flag because it is on the help page: http://ss64.com/nt/for2.html
and the double quotes are not mentioned on the for /d help page: http://ss64.com/nt/for_d.html

Offline

#5 19 Aug 2016 10:30

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 867
Website

Re: for escaping

Thanks for flagging this up npocmaka, I'm travelling at the moment but will fix up that page in a few days time.

Offline

#6 20 Aug 2016 12:23

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 139

Re: for escaping

npocmaka wrote:

Though I'm pretty sure this worked on older versions of windows (may be Vista...)

I can't get this to work in XP SP3.

Offline

Board footer

Powered by FluxBB