Windows batch: echo without new line
What is the Windows batch equivalent of the Linux shell command echo -n
which suppresses the newline at the end of the output?
The idea is to write on the same line inside a loop.
Solution 1:
Using set
and the /p
parameter you can echo without newline:
C:\> echo Hello World
Hello World
C:\> echo|set /p="Hello World"
Hello World
C:\>
Source
Solution 2:
Using: echo | set /p=
or <NUL set /p=
will both work to suppress the newline.
However, this can be very dangerous when writing more advanced scripts when checking the ERRORLEVEL becomes important as setting set /p=
without specifying a variable name will set the ERRORLEVEL to 1.
A better approach would be to just use a dummy variable name like so:echo | set /p dummyName=Hello World
This will produce exactly what you want without any sneaky stuff going on in the background as I had to find out the hard way, but this only works with the piped version; <NUL set /p dummyName=Hello
will still raise the ERRORLEVEL to 1.