Generating html with batch .. escape quotes

安稳与你 提交于 2019-11-30 06:02:51

问题


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

  1. don't escape the reserved chars if they are inside quotes
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!