286

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.

mklement0
  • 382,024
  • 64
  • 607
  • 775
gregseth
  • 12,952
  • 15
  • 63
  • 96
  • 3
    See [http://stackoverflow.com/questions/245395/underused-features-of-windows-batch-files/374361#374361][1] [1]: http://stackoverflow.com/questions/245395/underused-features-of-windows-batch-files/374361#374361 – Patrick Cuff Aug 18 '11 at 10:45
  • 2
    this got me nearly crazy..I knew `echo` could take `-n` but on the `cmd.exe` it just wouldn't work^^ – panny Feb 13 '13 at 11:32
  • 15
    @panny - Despite the common name, echo is not the same command between Windows and Posix. The same as nslookup, it has different options. So the comment "I knew `echo` could take `-n`" in the context of a question to do with Windows, is incorrect. – user66001 Jun 03 '13 at 18:03
  • @user66001 - "echoX -n" on Windows is detailed in an answer below posted today. – Bilbo Sep 12 '20 at 05:14
  • @Bilbo - Not sure about your use of batch, but 99% of the time I am using it to help automate something for someone else, on not-my-device. Not easy or efficient to supply a batch files with a 3rd party util. (especially if this 3rd party util is the .exe variety, given the virus landscape 7 years on from my original comment). – user66001 Sep 13 '20 at 06:15

20 Answers20

309

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

sbrajchuk
  • 48
  • 6
arnep
  • 5,971
  • 3
  • 35
  • 51
  • 107
    The pipe is very slow as it creates two extra cmd-tasks, faster is ` – jeb Aug 18 '11 at 18:23
  • 1
    @jeb just for curiosity: do you have any benchmark comparing how much slower my solution is? – arnep Aug 19 '11 at 11:52
  • 16
    It's nearly 15 times faster on my system – jeb Aug 22 '11 at 16:58
  • 32
    Add quotes around "Hello World" to prevent the extraneous space after the d. – Brian May 31 '12 at 19:45
  • 1
    I used this along with `echo`ing from a bat file into the clipboard with `|clip` [Clipboard Extender](http://www.clipboardextender.com/general-clipboard-use/command-window-output-to-clipboard-in-vista#comment-83255) showed me how to do it. `echo|set /p=mytext|clip` – TecBrat Jul 01 '13 at 19:16
  • 2
    As jeb has stated, SET /P has problems with certain leading characters. I've posted [a solution that should work in all cases on all Windows versions](http://stackoverflow.com/a/19468559/1012053) from XP onward. – dbenham Oct 20 '13 at 20:45
  • 17
    Warning: This will change ERRORLEVEL to 1. See answer by @xmechanix. – CoperNick May 12 '14 at 14:21
  • 8
    @user246694 `< nul` is a redirection from the `NUL` device. It contains nothing, but that is enough for `set /p` to stop waiting for user input – jeb Jul 17 '14 at 05:53
  • How do you write the output of `out` it hangs... – raphaelh Jul 22 '15 at 17:39
  • It doesn't use Unicode encoding even if it's specified. – Rick Jan 16 '17 at 13:56
  • weird... and has side effects like errorlevel set... not to mention cpu cycles... – ZEE Mar 12 '17 at 20:31
  • I found [this](http://jessekornblum.livejournal.com/271435.html) explanation of this technique. It is important there is no whitespace between the output text and the second pipe. – starfry Mar 28 '17 at 11:07
  • This approach does not work with `for` cycles, it will only print one line for the whole cycle(s). – Vlastimil Ovčáčík Aug 14 '17 at 13:14
  • To clear the errorlevel, `cmd /c "exit /b 0"` from this article: https://stackoverflow.com/questions/1113727/what-is-the-easiest-way-to-reset-errorlevel-to-zero?lq=1 @CoperNick I think your comment extremely valuable. – Jonathan Sep 24 '17 at 19:28
136

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.

Drarakel
  • 470
  • 3
  • 5
xmechanix
  • 1,395
  • 1
  • 8
  • 6
  • 31
    Warning: This command will set ERRORLEVEL to 0. If ERRORLEVEL was greater then 0 it will change ERRORLEVEL to 0. This also can be dangerous when writing more advanced scripts. (but +1 for answer) – CoperNick May 13 '14 at 07:42
  • 2
    So you basically need an IF ERRORLEVEL==0 (...) ELSE (...) just to not harm your environment in those circumstances. Sheesh. – SilverbackNet Sep 22 '17 at 00:33
  • 2
    well, writing more advanced batch scripts sounds pretty dangerous on its own already :) if not for stable execution, at least risky for the mental state of the writer – gilad905 May 12 '21 at 16:49
  • I'm not sure is "very dangerous" is the right phrase as it really depends on what the script is for and its potential repercussions. Maybe "this can cause unintended behavior" or something. – jordanbtucker Jan 27 '23 at 16:06
32

The simple SET /P method has limitations that vary slightly between Windows versions.

  • Leading quotes may be stripped

  • Leading white space may be stripped

  • Leading = causes a syntax error.

See http://www.dostips.com/forum/viewtopic.php?f=3&t=4209 for more information.

jeb posted a clever solution that solves most of the problems at Output text without linefeed, even with leading space or = I've refined the method so that it can safely print absolutely any valid batch string without the new line, on any version of Windows from XP onward. Note that the :writeInitialize method contains a string literal that may not post well to the site. A remark is included that describes what the character sequence should be.

The :write and :writeVar methods are optimized such that only strings containing troublesome leading characters are written using my modified version of jeb's COPY method. Non-troublesome strings are written using the simpler and faster SET /P method.

@echo off
setlocal disableDelayedExpansion
call :writeInitialize
call :write "=hello"
call :write " world!%$write.sub%OK!"
echo(
setlocal enableDelayedExpansion
set lf=^


set "str= hello!lf!world^!!!$write.sub!hello!lf!world"
echo(
echo str=!str!
echo(
call :write "str="
call :writeVar str
echo(
exit /b

:write  Str
::
:: Write the literal string Str to stdout without a terminating
:: carriage return or line feed. Enclosing quotes are stripped.
::
:: This routine works by calling :writeVar
::
setlocal disableDelayedExpansion
set "str=%~1"
call :writeVar str
exit /b


:writeVar  StrVar
::
:: Writes the value of variable StrVar to stdout without a terminating
:: carriage return or line feed.
::
:: The routine relies on variables defined by :writeInitialize. If the
:: variables are not yet defined, then it calls :writeInitialize to
:: temporarily define them. Performance can be improved by explicitly
:: calling :writeInitialize once before the first call to :writeVar
::
if not defined %~1 exit /b
setlocal enableDelayedExpansion
if not defined $write.sub call :writeInitialize
set $write.special=1
if "!%~1:~0,1!" equ "^!" set "$write.special="
for /f delims^=^ eol^= %%A in ("!%~1:~0,1!") do (
  if "%%A" neq "=" if "!$write.problemChars:%%A=!" equ "!$write.problemChars!" set "$write.special="
)
if not defined $write.special (
  <nul set /p "=!%~1!"
  exit /b
)
>"%$write.temp%_1.txt" (echo !str!!$write.sub!)
copy "%$write.temp%_1.txt" /a "%$write.temp%_2.txt" /b >nul
type "%$write.temp%_2.txt"
del "%$write.temp%_1.txt" "%$write.temp%_2.txt"
set "str2=!str:*%$write.sub%=%$write.sub%!"
if "!str2!" neq "!str!" <nul set /p "=!str2!"
exit /b


:writeInitialize
::
:: Defines 3 variables needed by the :write and :writeVar routines
::
::   $write.temp - specifies a base path for temporary files
::
::   $write.sub  - contains the SUB character, also known as <CTRL-Z> or 0x1A
::
::   $write.problemChars - list of characters that cause problems for SET /P
::      <carriageReturn> <formFeed> <space> <tab> <0xFF> <equal> <quote>
::      Note that <lineFeed> and <equal> also causes problems, but are handled elsewhere
::
set "$write.temp=%temp%\writeTemp%random%"
copy nul "%$write.temp%.txt" /a >nul
for /f "usebackq" %%A in ("%$write.temp%.txt") do set "$write.sub=%%A"
del "%$write.temp%.txt"
for /f %%A in ('copy /z "%~f0" nul') do for /f %%B in ('cls') do (
  set "$write.problemChars=%%A%%B    ""
  REM the characters after %%B above should be <space> <tab> <0xFF>
)
exit /b
dbenham
  • 127,446
  • 28
  • 251
  • 390
  • 2
    Nice to see a very powerful solution that can handle all characters – jeb Oct 19 '13 at 17:16
  • 3
    I'd like to point out that if the computer happens to have network connection to the internet that roughly this much of batch code can be used to download and install python or anything else on the computer which can get you rid of batch. Batch is fun however it's string capabilities are best for weekend challange. – n611x007 Jul 09 '15 at 11:12
  • @dbenham on line 6 "echo(" is that functionally the same as "echo." - not seen that before. – Skip R Aug 11 '18 at 02:17
  • 2
    @SkipR - Yes, it is functionally the same as `ECHO.`, [except `ECHO.` can fail under obscure circumstances](https://www.dostips.com/forum/viewtopic.php?f=3&t=774). There are a bunch of other forms that can also fail in obscure situations. The only one that always works is `ECHO(`. – dbenham Aug 11 '18 at 04:09
  • @dbenham: `ECHO(` is also failing, it returns errorlevel 9009 (see: [Official MS reference for cmd.exe %errorlevel% 9009](https://stackoverflow.com/questions/23091906/official-ms-reference-for-cmd-exe-errorlevel-9009) on Windows 11) – Luuk Jun 04 '23 at 13:09
11

A solution for the stripped white space in SET /P:

the trick is that backspace char which you can summon in the text editor EDIT for DOS. To create it in EDIT press ctrlP+ctrlH. I would paste it here but this webpage can't display it. It's visible on Notepad though (it's werid, like a small black rectangle with a white circle in the center)

So you write this:

<nul set /p=.9    Hello everyone

The dot can be any char, it's only there to tell SET /P that the text starts there, before the spaces, and not at the "Hello". The "9" is a representation of the backspace char that I can't display here. You have to put it instead of the 9, and it will delete the "." , after which you'll get this:

    Hello Everyone

instead of:

Hello Everyone

I hope it helps

Pedro
  • 111
  • 1
  • 2
  • 2
    I forgot to tell, it works in Windows 7 It won't work in a command line, only in a batch. For anyone not getting the char, download this example: http://pecm.com.sapo.pt/SET_with_backspace_char.txt – Pedro Jan 25 '15 at 21:43
  • Also true for Echo – Ben Personick Oct 24 '17 at 14:55
  • ... So, after doing a pretty damn thorough search I haven't found this ANYWHERE on the net. It might be the one time I've actually discovered something, and by dumb luck. For those who don't know you CAN enter control characters if you put your cmd prompt in legacy mode and use the right font. ... But if you simply redirect anything to a file or >con it works too. Seriously. Paste this EXACTLY into your command prompt: "echo ←c◙◙○○ Harharhar!!◙○○ -------------◙◙○○ I am the worst!?:'(○ ♪○NOPE!•♪○ I feel great! Hazzah-le-oop!◙◙○ I am programmeer hear me ... something.◙>con". – Brent Rittenhouse Feb 16 '19 at 03:11
  • Okay, I hope I found this out before anyone else but ... this is seemingly dependent on not being in a unicode code page. You could store the starting one in a variable do chcp 437, set the set in a variable, or output it, and then switch back (and it should still output). I'm playing around with it still. – Brent Rittenhouse Feb 16 '19 at 04:32
  • Also, does anyone have any idea why ←c clears the screen?! I can't find an instance of that anywhere on the net. It's specfically that combination, although you seem to be able to have whitespace between the two characters too. For any other character it seems to just.. remove the first character. I don't get it... – Brent Rittenhouse Feb 16 '19 at 04:33
  • Caution: This one passes the leading . and backspace, check the characters at receiving side. They do not show up when received string printed out. So, just for printing out it may not be important but when string is processed then it may cause confusion. Checked in Windows 10. – subcoder May 26 '20 at 13:06
  • Also, just backspace is fine, it works without any extra character like dot. So, receiver should remove the leading backspace when its required to process string, otherwise when directly printing, receiver should take care that backspace delete one character to the left(when there is not any dot). – subcoder May 26 '20 at 14:30
  • Instead of 9, the 8 would be the better placeholder here to indicate that the ACSII code for backspace is 8, whereas 9 represents tab. – jamacoe Apr 02 '23 at 05:19
  • Function to just output a space :echoBlank echo |set /p dummyVar=.◘[blank] goto :eof Substitute [blank] with the blank character and ◘with backspace. I entered it using a hex editor. – jamacoe Apr 02 '23 at 05:23
11

As an addendum to @xmechanix's answer, I noticed through writing the contents to a file:

echo | set /p dummyName=Hello World > somefile.txt

That this will add an extra space at the end of the printed string, which can be inconvenient, specially since we're trying to avoid adding a new line (another whitespace character) to the end of the string.

Fortunately, quoting the string to be printed, i.e. using:

echo | set /p dummyName="Hello World" > somefile.txt

Will print the string without any newline or space character at the end.

Joan Bruguera
  • 111
  • 1
  • 4
8

Here is another method, it uses Powershell Write-Host which has a -NoNewLine parameter, combine that with start /b and it offers the same functionality from batch.

NoNewLines.cmd

@ECHO OFF
start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 1 - ';Write-Host -NoNewLine 'Result 2 - ';Write-Host -NoNewLine 'Result 3 - '"
PAUSE

Output

Result 1 - Result 2 - Result 3 - Press any key to continue . . .

This one below is slightly different, doesn't work exactly like the OP wants, but is interesting because each result overwrites the previous result emulating a counter.

@ECHO OFF
start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 1 - '"
start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 2 - '"
start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 3 - '"
start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 4 - '"
start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 5 - '"
start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 6 - '"
start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 7 - '"
start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 8 - '"
start /b /wait powershell.exe -command "Write-Host -NoNewLine 'Result 9 - '"
PAUSE
Knuckle-Dragger
  • 6,644
  • 4
  • 26
  • 41
7

You can remove the newline using "tr" from gnuwin32 (coreutils package)

@echo off
set L=First line
echo %L% | tr -d "\r\n"
echo Second line
pause

By the way, if you are doing lots of scripting, gnuwin32 is a goldmine.

BearCode
  • 2,734
  • 6
  • 34
  • 37
  • I also suggest to [install git bash](http://git-scm.com/download/win). sure it's not the same as gnuwin32 (and it is a goldmine therefore +1), it's just a nice setup, and you have git-bash on the right mouse button nearly everywhere including the start menu button. – hakre Jan 26 '13 at 21:48
  • can you use tr to just remove the last space character, like in `trim`? – panny Feb 13 '13 at 12:50
  • use sed for trim: sed -e "s/ *$//" – BearCode Mar 05 '13 at 23:44
  • @panny - I cannot find a posix/linux util called trim. Also, `\r`, `\n` or `\r\n` (New lines in OSX, Posix and Windows respectively) are not "space" characters. – user66001 Jun 03 '13 at 18:11
  • 1
    If you have gnuwin32 (or git) installed, then you can use `printf` instead of `echo`. `printf` does not emit a line feed by default. – Ross Smith II May 06 '22 at 17:29
6

I made a function out of @arnep 's idea:

echo|set /p="Hello World"

here it is:

:SL (sameline)
echo|set /p=%1
exit /b

Use it with call :SL "Hello There"
I know this is nothing special but it took me so long to think of it I figured I'd post it here.

Mark Deven
  • 550
  • 1
  • 9
  • 21
4

DIY cw.exe (console write) utility

If you don't find it out-of-the-box, off-the-shelf, you can DIY. With this cw utility you can use every kind of characters. At least, I'd like to think so. Please stress-test it and let me know.

Tools

All you need is .NET installed, which is very common nowadays.

Materials

Some characters typed/copy-pasted.

Steps

  1. Create .bat file with the following content.
/* >nul 2>&1

@echo off
setlocal

set exe=cw
for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d  /o:-n "%SystemRoot%\Microsoft.NET\Framework\*csc.exe"') do set "csc=%%v"

"%csc%" -nologo -out:"%exe%.exe" "%~f0"

endlocal
exit /b %errorlevel%

*/

using System;

namespace cw {
    class Program {
        static void Main() {
            var exe = Environment.GetCommandLineArgs()[0];
            var rawCmd = Environment.CommandLine;
            var line = rawCmd.Remove(rawCmd.IndexOf(exe),exe.Length).TrimStart('"');
            line = line.Length < 2 ? "\r" : line.Substring(2) ;
            Console.Write(line);
        }
    }
}
  1. Run it.

  2. Now you have a nice 4KB utility so you can delete the .bat.

Alternatively, you can insert this code as a subroutine in any batch, send the resulting .exe to %temp%, use it in your batch and delete it when you're done.

How to use

If you want write something without new line:
cw Whatever you want, even with "", but remember to escape ^|, ^^, ^&, etc. unless double-quoted, like in "| ^ &".

If you want a carriage return (going to the beginning of the line), run just
cw

So try this from command line:

for /l %a in (1,1,1000) do @(cw ^|&cw&cw /&cw&cw -&cw&cw \&cw)
cdlvcdlv
  • 952
  • 1
  • 9
  • 22
  • I was inspired by your answer and created [this](https://github.com/riezebosch/setvar) little tool with Go and [this](https://marketplace.visualstudio.com/items?itemName=riezebosch.setvar) accompanying task for Azure Pipelines. It just grabs the stdout that is piped in and outputs that in a specific format to be picked up by the build. Thank you! – riezebosch Nov 14 '18 at 20:06
3

Sample 1: This works and produces Exit code = 0. That is Good. Note the "." , directly after echo.

C:\Users\phife.dog\gitrepos\1\repo_abc\scripts #
@echo.| set /p JUNK_VAR=This is a message displayed like Linux echo -n would display it ... & echo %ERRORLEVEL%

This is a message displayed like Linux echo -n would display it ... 0

Sample 2: This works but produces Exit code = 1. That is Bad. Please note the lack of ".", after echo. That appears to be the difference.

C:\Users\phife.dog\gitrepos\1\repo_abc\scripts #
@echo | set /p JUNK_VAR=This is a message displayed like Linux echo -n would display it ... & echo %ERRORLEVEL%

This is a message displayed like Linux echo -n would display it ... 1

3

From here

<nul set /p =Testing testing

and also to echo beginning with spaces use

echo.Message goes here
2

Maybe this is what your looking for, it's a old school script... :P

set nl=^& echo. 
echo %nl%The%nl%new%nl%line%nl%is%nl%not%nl%apparent%nl%throughout%nl%text%nl%
echo only in prompt.
pause

or maybe your trying to replace a current line instead of writing to a new line? you can experiment with this by removing the "%bs%" after the "." sign and also by spacing out the other "%bs%" after the "Example message".

for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "bs=%%a"
<nul set /p=.%bs%         Example message         %bs%
pause

I find this really interesting because it uses a variable for a purpose other than what it is intended to do. as you can see the "%bs%" represents a backspace. The second "%bs%" uses the backspace to add spaces after the "Example message" to separate the "Pause command's output" without actually adding a visible character after the "Example message". However, this is also possible with a regular percentage sign.

zask
  • 181
  • 1
  • 6
  • 3
    I see this `set nl=^& echo.` trick everywhere and the name of the variable is misleading. %nl% is **not** a newline **character**: it expands to `&echo.` so in the end you are running a new `echo` command every time, hence the newline. You can check it out writing `echo "%nl%The%nl%new%nl%line%nl%is%nl%not%nl%apparent%nl%throughout%nl%text%nl%"`. You get `"& echo. The& echo. new& echo. line& echo. is& echo. not& echo. apparent& echo. throughout& echo. text& echo. "`, revealing the trick. The output is the same but not for the reasons you suggest. – cdlvcdlv Jul 16 '18 at 09:25
  • not only is the 'trick' annoying, `ECHO.xxx` is actually ***parsed as a file*** before it is executed as a command, so it'll fail if there is a file named `ECHO` in the current directory. Better is `echo(` – ScriptKidd Jul 19 '20 at 10:30
2

Inspired by the answers to this question, I made a simple counter batch script that keeps printing the progress value (0-100%) on the same line (overwritting the previous one). Maybe this will also be valuable to others looking for a similar solution.

Remark: The * are non-printable characters, these should be entered using [Alt + Numpad 0 + Numpad 8] key combination, which is the backspace character.

@ECHO OFF

FOR /L %%A in (0, 10, 100) DO (     
    ECHO|SET /P="****%%A%%"    
    CALL:Wait 1
)

GOTO:EOF

:Wait
SET /A "delay=%~1+1"
CALL PING 127.0.0.1 -n %delay% > NUL
GOTO:EOF
Spinicoffee
  • 171
  • 2
  • 8
1

You can suppress the new line by using the set /p command. The set /p command does not recognize a space, for that you can use a dot and a backspace character to make it recognize it. You can also use a variable as a memory and store what you want to print in it, so that you can print the variable instead of the sentence. For example:

@echo off
setlocal enabledelayedexpansion
for /f %%a in ('"prompt $H & for %%b in (1) do rem"') do (set "bs=%%a")
cls
set "var=Hello World! :)"
set "x=0"

:loop
set "display=!var:~%x%,1!"
<nul set /p "print=.%bs%%display%"
ping -n 1 localhost >nul
set /a "x=%x% + 1"
if "!var:~%x%,1!" == "" goto end
goto loop

:end
echo.
pause
exit

In this way you can print anything without a new line. I have made the program to print the characters one by one, but you can use words too instead of characters by changing the loop.

In the above example I used "enabledelayedexpansion" so the set /p command does not recognize "!" character and prints a dot instead of that. I hope that you don't have the use of the exclamation mark "!" ;)

1

Use EchoX.EXE from the terrific "Shell Scripting Toolkit" by Bill Stewart
How to suppress the linefeed in a Windows Cmd script:

@Echo Off
Rem Print three Echos in one line of output
EchoX -n "Part 1 - "
EchoX -n "Part 2 - "
EchoX    "Part 3"
Rem

gives:

Part 1 - Part 2 - Part 3
{empty line}
d:\Prompt>

The help for this usage is:

Usage: echox [-n] message
  -n       Do not skip to the next line.
  message  The text to be displayed.

The utility is smaller than 48K, and should live in your Path. More things it can do:
- print text without moving to the next line
- print text justified to the left, center, or right, within a certain width
- print text with Tabs, Linefeeds, and Returns
- print text in foreground and background colors

The Toolkit includes twelve more great scripting tricks.
The download page also hosts three other useful tool packages.

Bilbo
  • 358
  • 1
  • 10
1

I found this simple one-line batch file called "EchoPart.bat" to be quite useful.

@echo | set /p=%*

I could then write something like the line below even on an interactive CMD line, or as part of a shortcut. It opens up a few new possibilities.

echopart "Hello, " & echopart "and then " & echo Goodbye

enter image description here

And if you're using it in batch files, the texts can be got from parameter variables instead of immutable strings. For instance:

@echopart Hello %* & @echo , how are you?

So that executing this line in "SayHello.bat" allows:

enter image description here

or even...

enter image description here

Have a play, and have fun!

Alex T
  • 375
  • 3
  • 8
  • I know the batch file line "@echo Hello %*, how are you?" would do the same, but the point about "EchoPart.bat" is that it outputs its text without adding a linefeed. This means that you can concatenate texts much like the "cat" command in BASH. Although you wouldn't have to pipe the commands, merely execute them sequentially. In my example tests I ended with a straight echo, but I could have ended with another echoPart. – Alex T Aug 16 '21 at 15:09
  • Compare for instance the command lines "dir" and "echopart Local &dir". Spot the difference? – Alex T Aug 16 '21 at 15:17
0

Echo with preceding space and without newline

As stated by Pedro earlier, echo without new line and with preceding space works (provided "9" is a true [BackSpace]).

<nul set /p=.9    Hello everyone

I had some issues getting it to work in Windows 10 with the new console but managed the following way.
In CMD type:

echo .◘>bs.txt

I got "◘" by pressing [Alt] + [8]
(the actual symbol may vary depending upon codepage).

Then it's easy to copy the result from "bs.txt" using Notepad.exe to where it's needed.

@echo off
<nul set /p "_s=.◘    Hello everyone"
echo: here
Magnus
  • 31
  • 1
  • 1
  • 4
0

With jscript:

@if (@X)==(@Y) @end /*
    @cscript //E:JScript //nologo "%~nx0" %*
    @exit /b %errorlevel%
*/if(WScript.Arguments.Count()>0) WScript.StdOut.Write(WScript.Arguments.Item(0));

if it is called write.bat you can test it like:

call write.bat string & echo _Another_String_

If you want to use powershell but with cmd defined variables you can use:

set str=_My_StrinG_
powershell "Write-Host -NoNewline ""%str%""""  & echo #Another#STRING#
npocmaka
  • 55,367
  • 18
  • 148
  • 187
0

I believe there's no such option. Alternatively you can try this

set text=Hello
set text=%text% world
echo %text%
m0skit0
  • 25,268
  • 11
  • 79
  • 127
-1

Late answer here, but for anyone who needs to write special characters to a single line who find dbenham's answer to be about 80 lines too long and whose scripts may break (perhaps due to user-input) under the limitations of simply using set /p, it's probably easiest to just to pair your .bat or .cmd with a compiled C++ or C-language executable and then just cout or printf the characters. This will also allow you to easily write multiple times to one line if you're showing a sort of progress bar or something using characters, as OP apparently was.

Community
  • 1
  • 1
  • @jiggunjer You sure? `printf`ing from a Win-7 `cmd` pane gives me `"'printf' is not recognized as an internal or external command, operable program or batch file."` – Seldom 'Where's Monica' Needy Sep 02 '16 at 18:03
  • `printf` is not native to windows. This is a windows question. – kayleeFrye_onDeck Sep 29 '16 at 17:57
  • 1
    @kayleeFrye_onDeck I assume your comment is directed at [jiggunjer](http://stackoverflow.com/questions/7105433/windows-batch-echo-without-new-line/30174981?noredirect=1#comment65904770_30174981), not me; I suggest in my question that C and C++ might be used as a fairly platform-independent alternative to shell commands in cases where formatting is important. – Seldom 'Where's Monica' Needy Sep 29 '16 at 22:34
  • 1
    Forgive me father, for I have skimmed. – kayleeFrye_onDeck Sep 30 '16 at 00:24
  • But then the input to the shell needs to be parsed correctly. For example, how would such a program print a quotation mark? – Alex Mar 20 '17 at 22:06