I have this line in the file .bat
for /L %%a in (1,1,3)DO echo %%a
What prints:
1
2
3
But I want you to print on the same line, this way:
1 2 3
I have this line in the file .bat
for /L %%a in (1,1,3)DO echo %%a
What prints:
1
2
3
But I want you to print on the same line, this way:
1 2 3
set
with the /P
parameter to avoid line wrapping.
The following two batches produce the desired effect:
@echo off
for /L %%a in (1,1,3)DO echo|set /p="%%a "
and
@echo off
for /L %%a in (1,1,3)DO <nul set /p="%%a "
The /p
is usually used for input with a prompt , so it does not break any lines. Combining the input with an artificial input, which comes from a echo
with pipe in the first example and a nul
instead of stdin of the second, we have the effect of showing the prompt without breaking lines, and without waiting for the input .
The second option apparently has a higher performance, which can be evaluated with more extensive tests (larger loops, for example).
1. Gambiarra