Problem with 'do <var> /L ....' and spaces

Jul 7, 2008
18
1
#1
I am using the do command with literal strings (/L) to automate some tasks. The problem I am having is that do insists on breaking up literal strings with embedded spaces, even if they are inside quotes ("") or %@quote[]. A simple example:

do v /L abc "def ghi" jkl (echo %v)

results in 4 echo'd lines of abc, "def, ghi", jkl (and the same if I use %@quote[def ghi]).

The documentation states that it treats everything in the stringset after /L as string literals, so I would expect quoted strings to be honored.

version: TCC 15.01.52 x64 Windows 7 [Version 6.1.7601]
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,509
46
Albuquerque, NM
prospero.unm.edu
#2
Working as designed (but no, I don't like this behavior either.)

You could work around it by reading your strings from a here-document instead:

Code:
@echo off

( do v in @con: ( echo %v ) ) <<- endtext
  abc
  def ghi
  jkl
endtext
 
Jul 7, 2008
18
1
#5
Working as designed (but no, I don't like this behavior either.)
Thanks for the workaround -- I had already done something similar but hadn't thought about using a here-document.

As for working as designed ... maybe. But I don't believe it is working as documented. The manual reads "once for every string literal in stringset" and a string literal is almost universally accepted as any sequence of characters enclosed in quotes. This behavior is definitely unexpected.
 

rconn

Administrator
Staff member
May 14, 2008
10,326
94
#6
I am using the do command with literal strings (/L) to automate some tasks. The problem I am having is that do insists on breaking up literal strings with embedded spaces, even if they are inside quotes ("") or %@quote[]. A simple example:

do v /L abc "def ghi" jkl (echo %v)

results in 4 echo'd lines of abc, "def, ghi", jkl (and the same if I use %@quote[def ghi]).

The documentation states that it treats everything in the stringset after /L as string literals, so I would expect quoted strings to be honored.
WAD - quotes are meaningless in strings; they only have a special meaning when the argument is a filename.

If you want to use quotes as delimiters, use the /T option. For example:

Code:
do v in /T"^"" /L abc "def ghi" jkl (echo %v)
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,509
46
Albuquerque, NM
prospero.unm.edu
#7
If you want to use quotes as delimiters, use the /T option. For example:

Code:
do v in /T"^"" /L abc "def ghi" jkl (echo %v)
That's not quite the same thing. The /T"^"" prevents spaces from being treated as delimiters, so you'll wind up with spaces at the beginning or the end of the value; and arguments won't be broken even at unquoted spaces. Perhaps:

Code:
do v in /T"," /L abc,def ghi,jkl ( echo %v )