'Simple' command script assistance :)

Discussion in 'Scripting' started by burfadel, Apr 27, 2015.

  1. burfadel

    burfadel MDL EXE>MSP/CAB

    Aug 19, 2009
    2,627
    3,856
    90
    #1 burfadel, Apr 27, 2015
    Last edited by a moderator: Apr 20, 2017
    As an example that I can use for another project, how do I get:
    Code:
    @echo off
    set example="one a" "two b" "three c" "four d" "five e"
    for /f "delims=" %%G in ('%example%') do (echo %%G)
    pause

    Such that it returns:
    one a
    two b
    three c
    four d
    five e

    or
    "one a"
    "two b"
    "three c"
    "four d"
    "five e"

    Of course, then displaying the pause command. That was there if running the script in Windows so it doesn't exit on you!

    Either of the above is fine for the intended purpose :)

    Thanks!
     
  2. burfadel

    burfadel MDL EXE>MSP/CAB

    Aug 19, 2009
    2,627
    3,856
    90
    #2 burfadel, Apr 27, 2015
    Last edited by a moderator: Apr 20, 2017
    (OP)
    I worked it out... with help of Google :p

    The above works as:
    Code:
    @echo off
    setlocal enableextensions enabledelayedexpansion
    set example="one a";"two b";"three c";"four d";"five e"
    
    call :start example
    goto :eof
    
    :start
    for /f "tokens=1,* delims=;" %%a in ("!%1!") do (set %1=%%b&echo %%a)
    if "!%1!" neq "" goto :start
    
    pause
    
    outputting:
    (then of course, the pause prompt since that was stated)
     
  3. burfadel

    burfadel MDL EXE>MSP/CAB

    Aug 19, 2009
    2,627
    3,856
    90
    #3 burfadel, Apr 27, 2015
    Last edited by a moderator: Apr 20, 2017
    (OP)
    I worked it out... with help of Google :p

    The above works as:
    Code:
    @echo off
    setlocal enableextensions enabledelayedexpansion
    set example="one a";"two b";"three c";"four d";"five e"
    
    call :start example
    pause
    
    :start
    for /f "tokens=1,* delims=;" %%a in ("!%1!") do (set %1=%%b&echo %%a)
    if "!%1!" neq "" goto :start
    
    outputting:
    (then of course, the pause prompt since that was stated)