for delims and eol

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

for delims and eol

#1 Post by Ed Dyreen » 14 Jul 2015 08:08

Something I don't understand about EOL and delims.

If I test the default EOL value ';' using echo ';' inside a for then ';;' is replaced with a space.

But if I use call "%0" it is not.

what's happening ?

Code: Select all

@echo off

if /I "%~1" == "/func" (

   echo.::3A#;;3B#
   exit
)

for /f "delims=" %%A in ('echo.::3A#;;3B#') do (

   echo.%%A
)

for /f "delims=" %%A in ('call "%~0" /func') do (

   echo.%%A
)

pause
exit

Code: Select all

::3A# 3B#
::3A#;;3B#
Druk op een toets om door te gaan. . .

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: for delims and eol

#2 Post by dbenham » 14 Jul 2015 08:23

This has nothing to do with DELIMS or EOL.

You are forgetting that the IN() clause is run in a new CMD process, with command line context, so it gets parsed an extra time. The semicolon is one of the token delimiters, so it must be escaped (unless it is quoted).

Code: Select all

for /f "delims=" %%A in ('echo.::3A#^;^;3B#') do echo(%%A

The command is run via CMD /C, which will remove enclosing quotes (if present). So the other option is to add double quotes around the entire command.

Code: Select all

for /f "delims=" %%A in ('"echo.::3A#;;3B#"') do echo(%%A
This works great in this case. But if your command already uses quotes, then you have to be careful about what is quoted when.

Dave Benham

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: for delims and eol

#3 Post by Ed Dyreen » 14 Jul 2015 09:33

Right, I conclude that according to these tests the default delim character is a space.

Code: Select all

for %%A in (he,hi ho) do (

   echo.%%A
)

for /f "delims=" %%A in ('"echo.he,hi ho"') do (

   echo.%%A
)

for /f %%A in ('"echo.he,hi ho"') do (

   echo.%%A
)

pause
exit

Code: Select all

he
hi
ho
he,hi ho
he,hi
Druk op een toets om door te gaan. . .

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: for delims and eol

#4 Post by dbenham » 14 Jul 2015 09:40

Not quite. The default value of space and tab is documented. Here is an extract of FOR /?

Code: Select all

       delims=xxx      - specifies a delimiter set.  This replaces the
                         default delimiter set of space and tab.


Dave Benham

Post Reply