Tuesday, September 17, 2013

4. Batch Files - All about echo, How to echo without newline



ECHO
One of the most frequently used command is echo
Echo can be used in 3 ways
Echo  :: will tell you echo is on or off 
echo Hello, world!  :: prints message on screen
@echo :: @ makes sure this line does not get echoed
 ::most common use of this is to turn echo off, otherwise all the commands would get printed on the screen, with echo off, only the stuff you choose to echo will get displayed
@echo off           

Echo without newline character
You will notice that whenever you use echo command, it append a new line character in the end.
Believe me, pretty soon after you start to write batch files, you would want to do echo without new line. Here is the solution for you.

Suppose you want to echo "Hello, World" without new line

echo | set /p dummyVar="Hello, World"
::Similarly if you have variable you, can echo that as well
set var1="Hello, World 2!"
echo | set /p dummyVar=%var1% 


There is a exe called "clip" which can be used to copy stuff to clipboard. you can use. This would copy "Hello, World" to clipboard without any newline character

echo | set /p dummyVar="Hello, World" | clip 



No comments: