Displays messages, or turns command echoing on or off.
Examples:
echo on
@echo off
echo Hello
echo "hello"
Displays the quotes too.
echo %PATH%
Displays the contents of PATH
variable.
echo Owner ^& son
Uses caret (^
) to escape ampersand (&), thereby enabling echoing ampersands.
echo 1&echo 2&echo 3
Displays three strings, each followed by a newline.
echo.
Outputs a newline while the period is not being output. Without the period, outputs echo off
or echo on
. Adding a space before the period leads to the period being output. Other characters having the same effect as period include :;,/\\(=+[]
.
echo %random%>>MyRandomNumbers.txt
While it seems to output random numbers to MyRandomNumbers.txt
, it actually does not do so for numbers 0-9, since these, when placed before >>
, indicate which channel is to be redirected. See also redirection.
echo 2>>MyRandomNumbers.txt
Instead of echoing 2, redirects standard error to the file.
(echo 2)>>MyRandomNumbers.txt
Echoes even a small number (in this case 2) and redirects the result.
>>MyRandomNumbers.txt echo 2
Another way to echo even a small number and redirect the result.
Displaying a string without a newline requires a trick:
set <NUL /p=Output of a command:
Displays "Output of a command:". The output of the next command will be displayed immediately after :
.
set <NUL /p=Current time: & time /t
Displays "Current time: " followed by the output of time /t
.
(set <NUL /p=Current time: & time /t) >tmp.txt
Like before, with redirecting the output of both commands to a file.
Links: