【问题标题】:Generating html with batch .. escape quotes使用批处理生成 html .. 转义引号
【发布时间】:2011-12-18 01:04:51
【问题描述】:

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

@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

它也有效,但问题是,我无法删除/转义引号,但这会让人歇斯底里。

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

【问题讨论】:

标签: html batch-file escaping quotes


【解决方案1】:

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

几个cmets

  1. 如果保留字符在引号内,请不要转义它们
  2. 如果 ( and ) 不在 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-16
    • 2011-01-14
    • 2019-06-12
    • 1970-01-01
    • 2012-10-10
    • 1970-01-01
    • 2021-06-05
    相关资源
    最近更新 更多