问题
This is supposed to generate the hierarchy to a web document with the different files, it's because I'm lazy I made this.
@echo off
echo.
echo This program will generate the base folder for a new website .. .
pause
md folders
echo > folders/default.html "<html> /* More content */ </html>"
echo > folders/style.css " /* All the standards i always use */ "
echo > folders/javascript.js " /* All the standards i always use */ "
echo.
exit
It also work but the problem is, I cannot remove/escape the quotes and that give hysterical moments though.
I tried many different things. Changing echo with type, I tried the different escape options I could find on www etc., but the quotes still there.
回答1:
You need to escape all the CMD reserved characters <
>
|
^
(
)
and &
with a caret ^
.
A couple of comments
- don't escape the reserved chars if they are inside quotes
- don't need to escape ( and ) if they are not in IF or FOR or inside another parentheses block.
a more complete example is
echo ^<!DOCTYPE HTML PUBLIC^> >index.html
echo ^<html^> >>index.html
echo ^<!-- more content --^> >>index.html
echo ^<!-- you don't need to escape ( ) outside blocks --^> >>index.html
echo ^<!-- don't escape inside quotes "&" --^> >>index.html
echo ^</html^> >>index.html
来源:https://stackoverflow.com/questions/7942330/generating-html-with-batch-escape-quotes