使用批处理生成html ..转义引号

MeN*_*oob 2 html quotes escaping batch-file

这应该生成具有不同文件的Web文档的层次结构,这是因为我很懒,我做了这个.

@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
Run Code Online (Sandbox Code Playgroud)

它也有效,但问题是,我不能删除/逃避引号,但这给了歇斯底里的时刻.

我尝试了很多不同的东西.用类型改变回声,我尝试了我可以在www等上找到的不同的转义选项,但引号仍然存在.

PA.*_*PA. 9

您需要转义所有CMD保留字符 < > | ^ ( )&使用插入符号^.

几条评论

  1. 如果它们在引号内,则不要逃避保留的字符
  2. 如果它们不在IF或FOR中或在另一个括号内,则不需要转义(和).

一个更完整的例子是

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
Run Code Online (Sandbox Code Playgroud)