gpt4 book ai didi

batch-file - 如何将大于和小于添加到批处理文件变量中

转载 作者:行者123 更新时间:2023-12-03 12:29:48 28 4
gpt4 key购买 nike

当我尝试

@echo off
set PTag=^<BR^>
echo %PTag%

我什么也没得到。

现在有趣的是,如果在最后一个回显之后有一个空行,我将得到:
The syntax of the command is incorrect.

如果我删除@echo,那么它实际上输出
echo <BR>

我想在变量内添加各种HTML标记,然后将这些变量连接起来以创建将在文件中输出的HTML。

最佳答案

set PTag=^<BR^>将值<BR>设置为PTag当您运行echo %PTag%时,它将扩展为echo <BR>,这是无效的重定向。您需要使用此转义<中的>PTag

set PTag=^^^<BR^^^>
第一个 ^自行转义,然后下一个 <>转义
你也可以用这个
set "PTag=^<BR^>"

第二种原因:引号 ^失去其特殊含义

If it is a quote (") toggle the quote flag, if the quote flag is active, the following special characters are no longer special: ^ & | < > ( ).


How does the Windows Command Interpreter (CMD.EXE) parse scripts?

most special characters (^ & ( ) < > | and also the standard delimiters , ; = SPACE TAB) lose their particular meaning as soon as ther are placed in between "", and the "" themselves do not become part of the variable value


Special Characters in Batch File

现在,该变量将在其中包含值 ^<BR^>,并将其扩展为 echo %PTag%,以
echo ^<BR^>
这是一个有效的命令

关于batch-file - 如何将大于和小于添加到批处理文件变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43349134/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com