Let\'s say I have a batch file that has \"padding\" in it, and I want to indent the beginning of the prompt string for the user to type in. If I use spaces, it will not show up
dbenhams answer works good when you only want to display the text, but not if you create a file, as it inputs also the backspaces.
But for files(and for displaying) you can use copy /a
to remove a CR/LF with the help of a SUB(EOF) character.
The trick is to append the SUB
character directly after the text, so it's just before the CR/LF
of the ECHO output.
And then using the /a
switch of the copy command will only copy the content to the SUB character, so the SUB
and also the CR/LF
are removed
@echo off
setlocal EnableDelayedExpansion
call :createSub
call :echoWithoutLinefeed "=hello"
call :echoWithoutLinefeed " world"
exit /b
:echoWithoutLinefeed
> txt.tmp (echo(%~1!sub!)
copy txt.tmp /a txt2.tmp /b > nul
type txt2.tmp
del txt.tmp txt2.tmp
exit /b
:createSub
copy nul sub.tmp /a > nul
for /F %%a in (sub.tmp) DO (
set "sub=%%a"
)
del sub.tmp
exit /b