Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to echo "2" (no quotes) to a file, from a batch script?

How do I echo the number 2 into a file, from a batch script?

This doesn't work:

Echo 2>> file.txt 

because 2>> is a special command. :(

like image 627
user541686 Avatar asked Aug 29 '11 02:08

user541686


People also ask

How do you echo a blank line in a batch file?

To create a blank line in a batch file, add an open bracket or period immediately after the echo command with no space, as shown below. Adding @echo off at the beginning of the batch file turns off the echo and does not show each of the commands. @echo off echo There will be a blank line below. echo.

What is @echo off in batch script?

batch-file Echo @Echo off @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.

How do I echo a variable in a batch file?

Please open a command prompt window, run set /? and read the output help. The syntax is set /P variable=prompt text or better set /P "password=Enter your password: " . And please note that variable password keeps its current value if already defined and user hits just RETURN or ENTER.


2 Answers

Little-known feature: The redirection operator can go anywhere on the line.

>>file.txt echo 2 
like image 138
Raymond Chen Avatar answered Oct 04 '22 05:10

Raymond Chen


Use (ECHO 2)>>file.txt. This will output 2 without any spaces.

like image 43
Dominic K Avatar answered Oct 04 '22 04:10

Dominic K