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

ECHOS and trailing spaces

Discussion in 'Support' started by JohnQSmith, Jun 18, 2012.

  1. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    Working on a solution for Scott's post. Had to make some more sample data so I wrote a quick btm.
    Code:
    do a = 1 to 100 (
        do b = 1 to %@random[14,20] (
            set c=%@convert[10,16,%@random[0,255]]
            iff %@len[%c]== 1 then
                echos 0%c` `
            else
                echos %c` `
            endiff
        )
        echo.
    )
    I've tried with a trailing space enclosed in backquotes (as in the code above) and also with a space after the %c followed by double backquotes. Neither will output spaces between the echos. In other words, I'm getting this
    Code:
    F000780382478ABAA474DF8BEC5B31CA6A8C1642
    7A8766DF9639DB844D3AB253A8DCAE1572
    F26AD92D781FBEE6ED4EFC14958E25
    7A7150FD3DEC99E3AE32419FD6B59E7818C9
    2A5BC47BBE76B63C40AB533D9EBC4C2B4C59D7
    C6A7F358AF3C3FD5CCB3CB51023F66D54963C5
    Instead of this
    Code:
    0B 02 59 F5 68 18 57 6A 48 B6 C7 E4 68 DB 3F 30
    52 68 2A 45 3C 0D FB AB 12 E8 EF D9 77 49 00
    7F 04 41 B0 A8 AB 65 19 5B 52 58 2E FA 3A BF
    C0 AF D2 68 EE E0 76 54 13 46 D4 17 0F 78 72 4B EC
    DC 9A 12 16 13 A0 F5 40 F8 D5 AC 82 44 64
    4A 30 84 61 29 BF C0 4E 13 E7 BA AA E5 FA 8A 59 81 AF 6F
    If I put an additional space between the ECHOS and the %c, I do get spaced output, but I want trailing spaces, not leading spaces.

    Edit: Problem is in both TCC 13.04.63 and 14.00.23 for Windows XP SP3
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,941
    Likes Received:
    30
    IIRC, this has been discussed a few times and the behavior has not changed. There's no such problem with FOR.
    Code:
    v:\> do i=1 to 3 (echos %i` `)
    123
    v:\> for /l %i in (1,1,3) echos %i` `
    1 2 3
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,941
    Likes Received:
    30
    This might help:
    Code:
    v:\> do i=1 to 3 (echos %i^k ^k)
    1 2 3
     
  4. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,304
    Likes Received:
    39
    As it's in a .BTM file, I recommend that you use a proper DO loop:

    Code:
    @echo off
    do a = 1 to 100
        do b = 1 to %@random[14,20]
            set c=%@convert[10,16,%@random[0,255]]
            iff %@len[%c]== 1 then
                echos 0%c` `
            else
                echos %c` `
            endiff
        enddo
        echo.
    enddo
    
    Using the parentheses essentially mashes the body of the loop onto a single command line -- a hack to make DO usable at the command line, not needed in a batch file. I don't fully understand the side effect that you're seeing, but I'm not at all surprised that there is a side effect.
     
  5. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    That works. I was using the parentheses as one would use curly brackets in C or Java.
     

Share This Page