So I am trying to make my batch file create a new batch file, and then have the created batch file edit a text file. For instance-
echo This is an edit >> text.txt >> text.bat
How would I be able to accomplish this? If you need more information, just reply here. Please help!
Using echo redirects inside of a redirect? (Help)
Moderator: DosItHelp
Re: Using echo redirects inside of a redirect? (Help)
Slight edit with that-
echo echo This is an edit >> text.txt >> text.bat
echo echo This is an edit >> text.txt >> text.bat
Re: Using echo redirects inside of a redirect? (Help)
Escape special characters.
^ to ^^
< to ^<
> to ^>
| to ^|
& to ^&
% to %%
Regards
aGerman
^ to ^^
< to ^<
> to ^>
| to ^|
& to ^&
% to %%
Regards
aGerman
Re: Using echo redirects inside of a redirect? (Help)
Thank you so much!
That was a big help! I finished it with-
echo echo This is an edit ^>^> text.txt >> text.bat
Question, Why does this work? I appreciate the solution, but could you help me learn why so I am better knowledged on this? Thank you!

echo echo This is an edit ^>^> text.txt >> text.bat
Question, Why does this work? I appreciate the solution, but could you help me learn why so I am better knowledged on this? Thank you!
Re: Using echo redirects inside of a redirect? (Help)
It's because each of these characters has its own functionality (escaping , redirection, piping, command concatenating, variable marking). You use >> to redirect the echo output to a file. To suppress their functionality and to let the cmd parse it as a literal character you have to escape them.
You could make some tests with the rules I gave you.
displays
These rules (except the last for %) are not valid for strings enclosed in quotation marks.
Also "EnableDelayedExpansion" changes the behavior for strings in variables and the exclamation mark is another special character that you have to escape in some cases.
Regards
aGerman
You could make some tests with the rules I gave you.
Code: Select all
echo ^^^<^>^|^&%%
displays
Code: Select all
^<>|&%
These rules (except the last for %) are not valid for strings enclosed in quotation marks.
Also "EnableDelayedExpansion" changes the behavior for strings in variables and the exclamation mark is another special character that you have to escape in some cases.
Regards
aGerman
Re: Using echo redirects inside of a redirect? (Help)
That is great to know; thank you so much for your help!