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
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:
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
3 thoughts on “How to make the echo command without new line in Windows”
Thank You much! Was very helpful!
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
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