- echo (вывод на экран) echo
- Синтаксис Syntax
- Параметры Parameters
- Комментарии Remarks
- Примеры Examples
- How to echo a new line in batch file
- 1. How to echo new line in batch file
- a. By creating a newline character:
- b. By using ‘EnableDelayedExpansion’:
- c. By using echo function call:
- 2. How to echo a blank line between command execution in batch file
- How can I insert a new line in a cmd.exe command?
- 7 Answers 7
- Use Alt codes with the numpad
- How to make the echo command without new line in Windows
- About Sergey Tkachenko
- 2 thoughts on “ How to make the echo command without new line in Windows ”
- Leave a Reply Cancel reply
- Connect with us
- Is it possible to put a new line character in an echo line in a batch file? [duplicate]
- 7 Answers 7
echo (вывод на экран) echo
Отображает сообщения или включает или отключает функцию вывода команд. Displays messages or turns on or off the command echoing feature. При использовании без параметров echo отображает текущее значение эха. If used without parameters, echo displays the current echo setting.
Синтаксис Syntax
Параметры Parameters
Параметр Parameter | Описание Description |
---|---|
[вкл. | Откл.] [on | off] | Включает или выключает функцию вывода команд. Turns on or off the command echoing feature. Команда по умолчанию включена. Command echoing is on by default. |
Задает текст, отображаемый на экране. Specifies the text to display on the screen. | |
/? /? | Отображение справки в командной строке. Displays help at the command prompt. |
Комментарии Remarks
echo Команда особенно полезна при отключенном эхо . The echo command is particularly useful when echo is turned off. Чтобы отобразить сообщение, которое содержит несколько строк без отображения команд, можно включить несколько echo команд после команды echo off в пакетной программе. To display a message that is several lines long without displaying any commands, you can include several echo commands after the echo off command in your batch program.
После выключения эхо Командная строка не отображается в окне командной строки. After echo is turned off, the command prompt doesn’t appear in the Command Prompt window. Чтобы отобразить командную строку, введите команду echo on. To display the command prompt, type echo on.
Если используется в пакетном файле, Включение и вывод не влияют на параметр в командной строке. If used in a batch file, echo on and echo off don’t affect the setting at the command prompt.
Чтобы предотвратить вывод определенной команды в пакетном файле, вставьте @ знак перед командой. To prevent echoing a particular command in a batch file, insert an @ sign in front of the command. Чтобы предотвратить вывод всех команд в пакетном файле, включите команду echo off в начале файла. To prevent echoing all commands in a batch file, include the echo off command at the beginning of the file.
Чтобы отобразить символ канала ( | ) или перенаправления ( или > ) при использовании эха, используйте знак крышки ( ^ ) непосредственно перед символом канала или перенаправления. To display a pipe ( | ) or redirection character ( or > ) when you are using echo, use a caret ( ^ ) immediately before the pipe or redirection character. Например,, ^| ^> или ^ ). For example, ^| , ^> , or ^ ). Чтобы отобразить курсор, введите две крышки подряд ( ^^ ). To display a caret, type two carets in succession ( ^^ ).
Примеры Examples
Чтобы отобразить текущее значение echo , введите: To display the current echo setting, type:
Чтобы вывести на экран пустую строку, введите: To echo a blank line on the screen, type:
Не включайте пробел перед точкой. Don’t include a space before the period. В противном случае вместо пустой строки отображается точка. Otherwise, the period appears instead of a blank line.
Чтобы запретить вывод команд в командной строке, введите: To prevent echoing commands at the command prompt, type:
Когда эхо отключено, Командная строка не отображается в окне командной строки. When echo is turned off, the command prompt doesn’t appear in the Command Prompt window. Чтобы снова отобразить командную строку, введите команду echo on. To display the command prompt again, type echo on.
Чтобы предотвратить отображение на экране всех команд в пакетном файле (включая команду echo off ), в первой строке типа пакетного файла: To prevent all commands in a batch file (including the echo off command) from displaying on the screen, on the first line of the batch file type:
Команду echo можно использовать как часть оператора If . You can use the echo command as part of an if statement. Например, чтобы найти в текущем каталоге любой файл с расширением. rpt и вывести сообщение при обнаружении такого файла, введите: For example, to search the current directory for any file with the .rpt file name extension, and to echo a message if such a file is found, type:
Следующий пакетный файл выполняет поиск файлов с расширением txt в текущем каталоге и выводит сообщение с указанием результатов поиска: The following batch file searches the current directory for files with the .txt file name extension, and displays a message indicating the results of the search:
Если при выполнении пакетного файла не найдены TXT-файлы, отображается следующее сообщение: If no .txt files are found when the batch file is run, the following message displays:
Если TXT-файлы найдены при запуске пакетного файла, отображаются следующие выходные данные (в этом примере предполагается, что файлы File1.txt, File2.txt и File3.txt существуют): If .txt files are found when the batch file is run the following output displays (for this example, assume the files File1.txt, File2.txt, and File3.txt exist):
How to echo a new line in batch file
If you are looking for a solution to echo a new line in batch file, this article explains various ways to insert a new line in a command prompt using a batch script.
We will consider 2 aspects of printing a new line in batch script.
- How to add a new line between text.
- How to add some blank lines between your command execution (batch echo blank line).
To echo a new line in a batch file, you can create a new line character as ^^^%NLC%%NLC%^%NLC%%NLC% and echo it or use echo; or echo( or echo/ or echo+ or echo= in a single line to insert a blank line in between your code. Also, by using EnableDelayedExpansion you can achieve the blank line.
You may need any one of them in different situations. When you are running a series of utilities in a single batch file, you may need to echo a blank line between utility execution to have a clear view of the command prompt. Learn how echo new line in batch file works.
1. How to echo new line in batch file
a. By creating a newline character:
@echo off
REM Begin
set NLC=^
set NL=^^^%NLC%%NLC%^%NLC%%NLC%
REM End
echo Hello%NL%World
Note: The main code is between the REM statement. The two spaces are mandatory.
Output:
Hello
World
b. By using ‘EnableDelayedExpansion’:
@echo off
setlocal EnableDelayedExpansion
(set \n=^
%=This is Mandatory Space=%
)
Note: In place of ‘This is Mandatory Space’, you can write anything of your own or just provide 4 spaces.
Output:
Hello
World
c. By using echo function call:
Note: In place of echo, you can use echo; or echo( or echo/ or echo+ or echo=
Though echo. or echo: also yields the same result still it is not recommended to use those, as it may slow the execution process.
Output:
Hello
World
2. How to echo a blank line between command execution in batch file
@echo Executing Command1
@echo,
@echo(
@echo Executing Command2
Output:
Executing Command1
Note: In place of echo, you can use echo; or echo( or echo/ or echo+ or echo=
echo. or echo: provides the same result but is not recommended to use, as they may slow down the execution process.
Some people recommend using ‘echo .’, it will print a dot(.) on the screen.
@echo Executing Command1
@echo .
@echo Executing Command2
Output:
Executing Command1
.
Executing Command2
That’s how you echo a new line in a batch file. Hope you will make use of any one of the methods mentioned above.
How can I insert a new line in a cmd.exe command?
I’m trying to execute a command on cmd.exe , with a line break or new line as part of the command, like below:
But every new line executes the command, instead of continuing the command on the next line.
So how can I input a new line character, or create a multi-line command in cmd.exe?
7 Answers 7
Use the ^ character as an escape:
I’m assuming you’re using cmd.exe from Windows XP or later. This is not actual DOS. If you are using actual DOS (MS-DOS, Win3.1, Win95, Win98, WinME), then I don’t believe there is an escape character for newlines. You would need to run a custom shell. cmd.exe will prompt you for More? each time you press enter with a ^ at the end of the line, just press enter again to actually escape/embed a newline.
Use Alt codes with the numpad
That line feed character can be entered as an Alt code on the CLI using the numpad: with NumLock on, hold down ALT and type 10 on the numpad before releasing ALT. If you need the CR as well, type them both with Alt+13 and then Alt+10 : ♪◙
Note: this will not work in a batch file.
Sample use case:
You are trying to read the %PATH% or %CLASSPATH% environment variables to get a quick overview of what’s there and in what order — but the wall of text that path returns is unreadable. Then this is something you can quickly type in:
How to make the echo command without new line in Windows
By default, the echo command adds a new line character to its output. For example, if you print some environment variable, the output will be appended with an extra line. The extra line can create a problem if you wish to copy the output to the clipboard to be used in another command. Today we will see how to get rid of the new line character in the echo command output at the command prompt.
There are several scenarios when you wouldn’t want the additional line. For example, if you are using a combination of «clip» and «echo» commands as described in the article How to copy the command prompt output directly to the Windows clipboard, the new line character will be a hindrance.
To remove it from the output, use the following syntax:
For example:
In case you need to use such syntax with the clip command, you need to use it as follows:
No new line character will be present in the clipboard:
That’s it.
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
Share this post
About Sergey Tkachenko
Sergey Tkachenko is a software developer from Russia who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube.
2 thoughts on “ How to make the echo command without new line in Windows ”
Thank You much! Was very helpful!
Best ragards,
Gennady
The pipe is very slow as it creates two extra cmd-tasks, faster is
Leave a Reply Cancel reply
Connect with us
We discontinued Facebook to deliver our post updates.
Is it possible to put a new line character in an echo line in a batch file? [duplicate]
Is it possible to put a new line character in an echo line in a batch file?
Basically I want to be able to do the equivalent of:
You can do this easily enough in Linux, but I can’t work out how to do it in Windows.
7 Answers 7
echo. prints an empty line.
20 times slower than echo( and it fails completly when a file exists with the name echo without extension. So echo( is safer and faster – jeb Sep 15 ’14 at 14:21
It can be solved with a single echo.
You need a newline character \n for this. There are multiple ways to get a new line into the echo
1) This sample use the multiline caret to add a newline into the command,
the empty line is required
2) The next solution creates first a variable which contains one single line feed character.
Or create the new line with a slightly modified version
And use this character with delayed expansion
To use a line feed character with the percent expansion you need to create a more complex sequence
Or you can use the New line hack
But only the delayed expansion of the newline works reliable, also inside of quotes.
After a little experimentation I discovered that it is possible to do it without issuing two separate echo commands as described in How can you echo a newline in batch files?. However to make it work you will need a text editor that does not translate CR to CR+LF.
then with NumLock on, hold down the ALT key and type 10 on the numeric keypad before releasing ALT (you must use the numeric keypad, not the top-row number keys). This will insert a CR character. Then type the second line. Depending on your editor and how it handles CR compared with CR+LF you may get:
This works from the command line and will work in a batch file so long as the text editor does not translate CR to CR+LF (which Windows/DOS editors do unless you configure them not to). If the CR is converted to CR+LF, or if you use just LF, the second line is interpreted as a new command.
However, I cannot see why this would be preferable over simply: