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:
echo | set /p=some text or variable
For example:
In case you need to use such syntax with the clip command, you need to use it as follows:
echo | set /p=some text or variable|clip
No new line character will be present in the clipboard:
That's it.
Support us
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!
Advertisеment
Thank You much! Was very helpful!
Best ragards,
Gennady
The pipe is very slow as it creates two extra cmd-tasks, faster is <nul set /p =Hello. set /p can't echo an equal sign as first character nor spaces/tabs. – jeb Aug 18 '11 at 18:23
ref: https://stackoverflow.com/questions/7105433/windows-batch-echo-without-new-line#comment8520146_7105690
Thank you! <nul set /p=my text
This worked in my project to output text to .js files from a batch with no leading/trailing spaces