0

i am trying to create a batch file that creates a file in batch (making a batch file within a batch file) and my code looks like this:

echo :1 >> defer.bat
echo echo %random% %random% %random% %random% %random% %random% %random% %random% >> matrix.bat
echo color a >> matrix.bat
echo goto 1 >> matrix.bat

but this is what i get in "matrix.bat":

:1 
echo 15001 22164 12657 22939 10057 23147 24690 21579 
color a 
goto 1 

and what i want is it to say is %random%

is there any way to make it say that?

(if your confused i want to replace echo 15001 22164 12657 22939 10057 23147 24690 21579 with echo %random% %random% %random% %random% %random% %random% %random% %random%

powerCodes
  • 11
  • 2
  • 2
    Does this answer your question? [Ignore percent sign in batch file](https://stackoverflow.com/questions/1907057/ignore-percent-sign-in-batch-file) (Specifically, use `%%random%%` instead of `%random%`.) – SomethingDark Jul 23 '21 at 22:22
  • 1
    Use `%%RANDOM%%` instead. Also in future please try to use the very useful search facility at the to of the page, there are plenty of questions and answers already on this site with the [[tag:batch-file]] tag, which need to `echo` a variable without expanding it. – Compo Jul 23 '21 at 22:24

1 Answers1

2

Yes, this is called "escaping", and is done a little differently in every programming language. Here's a chart for dos batch:

https://www.robvanderwoude.com/escapechars.php

As you can see in the first line of the table, the way to go about escaping a percentage sign, is the double %%, as follows:

echo echo %%random%% %%random%% %%random%% %%random%% %%random%% %%random%% %%random%% %%random%% >> matrix.bat

Good luck!

burt
  • 41
  • 4