1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Support' started by Niwotian60, Aug 20, 2013.

  1. Niwotian60

    Joined:
    Jul 7, 2008
    Messages:
    17
    Likes Received:
    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]
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    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
    
     
  3. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    Isn't there a suggestion pending in the Feedback forum for an option implementing the more commonly desired operation?
     
  4. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    Yes, there is.
     
  5. Niwotian60

    Joined:
    Jul 7, 2008
    Messages:
    17
    Likes Received:
    1
    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.
     
  6. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,804
    Likes Received:
    82
    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)
     
  7. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    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 )
    
     

Share This Page