Ticket #44058

FOR %%A IN () broken

Open Date: 2022-03-09 02:00 Last Update: 2022-03-13 23:07

Reporter:
Owner:
Type:
Status:
Closed
Component:
MileStone:
(None)
Priority:
5 - Medium
Severity:
5 - Medium
Resolution:
Fixed
File:
None

Details

(Split from https://osdn.net/projects/svardos/ticket/44051#comment:12510:44051:1646752457 and https://osdn.net/projects/svardos/ticket/44051#comment:12510:44051:1646756790)

@ECHO OFF
FOR %%A IN (A B) DO ECHO %%A

This would print:

A
B
with FreeCOM and MS command.com.

With the recent SvarCOM there is no output produced at all.

Same result, after replacing ECHO with TYPE.

Ticket History (3/13 Histories)

2022-03-09 02:00 Updated by: bttr
  • New Ticket "FOR %%A IN () broken" created
2022-03-09 02:10 Updated by: mateuszviste
Comment

well, it is not "broken", it was simply never implemented. :)

When reading the MSDOS help I saw "runs command for each file in a set of files". I didn't knew it could be also simple strings, so SvarCOM looks only for matching files.

This is very confusing, since it means that such command:

for %d in (*.txt *.doc) do echo %d

will print existing *.txt and *.doc files, while such command:

for %d in (file.txt file.doc) do echo %d

will print "file.txt" and "file.doc", whether or not such files exist.

I assume that the differentiator here is the presence of wildcards, but that's only a guess.

2022-03-09 03:24 Updated by: bttr
Comment

Reply To mateuszviste

well, it is not "broken", it was simply never implemented. :)

Oops!

When reading the MSDOS help I saw "runs command for each file in a set of files". I didn't knew it could be also simple strings, so SvarCOM looks only for matching files.

I see.

This is very confusing, since it means that such command: for %d in (*.txt *.doc) do echo %d will print existing *.txt and *.doc files, while such command: for %d in (file.txt file.doc) do echo %d will print "file.txt" and "file.doc", whether or not such files exist. I assume that the differentiator here is the presence of wildcards, but that's only a guess.

I think, you're right. (? can also be used)

2022-03-09 03:38 Updated by: bttr
Comment

About the separators supported:

For FreeCOM it's easy, because we just have to look at the source code:

#define isargdelim(ch) (isspace(ch) || iscntrl(ch) || strchr(",;=", ch))

For MS-DOS 5.0 and 6.22 command.com I found by testing:

  • SPACE (of course)
  • TAB
  • ;
  • ,
  • /
  • =
  • LF (CR does not work)

Other iscntrl() chars don't work. Also not working: '~?&*+-\.@!"%:<>|

So, FreeCOM behaves differently. Some would say, it has bugs.

(Edited, 2022-03-09 03:42 Updated by: bttr)
2022-03-09 05:45 Updated by: mateuszviste
Comment

thanks for the extensive research! rev 1055 supports the non-space delimiters and also processes expressions without wildcards (* or ?) as messages.

2022-03-10 21:26 Updated by: bttr
Comment

I built a new binary for testing.

Test batch file:

@ECHO OFF
FOR %%A IN (F\OO;BAR) DO ECHO A=%%A

I would expect the following output:

A=F\OO
A=BAR

But I get:

A=FF\OO
A=BAR

There is an issue with the backslash. This also still prevents WHICH.BAT to work.

Additionally I found, redirecting the batch file's output to a log file doesn't work. It just doesn't create a new file.

2022-03-10 21:29 Updated by: mateuszviste
Comment

Reply To bttr

Additionally I found, redirecting the batch file's output to a log file doesn't work. It just doesn't create a new file.

This is on purpose, it is not supposed to work.

2022-03-11 02:47 Updated by: bttr
Comment

Reply To mateuszviste

Reply To bttr

Additionally I found, redirecting the batch file's output to a log file doesn't work. It just doesn't create a new file.

This is on purpose, it is not supposed to work.

If you aim for SvarCOM being a drop-in replacement for MS command.com or FreeCOM, this needs to change.

2022-03-11 04:39 Updated by: mateuszviste
Comment

Reply To bttr

Reply To mateuszviste

Reply To bttr

Additionally I found, redirecting the batch file's output to a log file doesn't work. It just doesn't create a new file.

This is on purpose, it is not supposed to work.

If you aim for SvarCOM being a drop-in replacement for MS command.com or FreeCOM, this needs to change.

Can you tell which MS-DOS version allows to redirect the output of a bat file?

2022-03-11 05:32 Updated by: mateuszviste
Comment

Reply To bttr

Test batch file: {{{ @ECHO OFF FOR %%A IN (F\OO;BAR) DO ECHO A=%%A }}} I would expect the following output: {{{ A=F\OO A=BAR }}} But I get: {{{ A=FF\OO A=BAR }}}

Fixed in rev 1070.

2022-03-12 08:21 Updated by: bttr
Comment

For the record, this is from the PTS-DOS manual:

3.1.5 FOR Command
Purpose: Performs the FOR cycle.
Syntax: FOR %var IN (LIST) DO COMMAND
or
FOR [/?][/H[ELP]]
Parameters:
Var - one-letter variable (a-z or A-Z),
LIST - list of arguments with standard separators,
COMMAND - DOS command. It can contain the string "%var", that will be substituted for a value
from the LIST.
/? or /H or /HELP - help.
Note: The LIST elements are considered to be files or directories first, and then a text.

They just call it 'list' and 'list elements'. :-D

2022-03-13 22:56 Updated by: bttr
  • Status Update from Open to Closed
  • Resolution Update from None to Fixed
Comment

Fix confirmed for SvarCOM version 2022.3.

2022-03-13 23:07 Updated by: bttr
Comment

Reply To mateuszviste

Reply To bttr

Reply To mateuszviste

Reply To bttr

Additionally I found, redirecting the batch file's output to a log file doesn't work. It just doesn't create a new file.

This is on purpose, it is not supposed to work.

If you aim for SvarCOM being a drop-in replacement for MS command.com or FreeCOM, this needs to change.

Can you tell which MS-DOS version allows to redirect the output of a bat file?

Sorry, my fault. I was under the impression, that this would work in MS-DOS (6.22).

Attachment File List

No attachments

Edit

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » Login