问题描述
下面的例子:
关闭@echo
::语法检查忽略^<&符GT;一些复选框前pression之后
如果定义的路径^等等回声#
如果不存在C:\\ ^等等回声#
如果错误级别0 ^等等回声#
::但是在比较操作逃逸效果良好
如果1 ^等等== 1 ^等等回声#
为什么呢?结果
我不知道。
但似乎标记生成器在这种情况下,执行两次。
下面是要表明,标记生成器是独立 ECHO ON
回响
SETLOCAL EnableDelayedExpansion
设置VAR =你好你
如果!VAR! ==你好^你真正的呼应
如果!VAR! ==你好,你真正呼应
两条线都显示为如果!无功! ==你好,你真正的呼应
但只有前执行回声真正
,因为你好,你
是一个符号,但第二个样本不在家。
组VAR = 1
如果定义VAR ^爆炸回声VAR定义
但作为dbenham解释的那样,如果定义
和(如果存在)
似乎第一记号化它象预期的那样第二个字将不被用作命令,但它完全地丢弃。
的interessting效果是一个FOR参数和延迟扩展不受影响,虽然这些相都直接跟随的回波相的
所以,我认为,有由使用其他标记生成器如果定义
和(如果存在)
对比 IF ..<比较方式>
使用 ECHO ON
(如JosefZ提到的),你可以看到不同之处。
如果!无功! ==你好^你真正的呼应
如果定义你好^你回音定义
输出
C:\\ TEMP>如果无功! ==你好,你真正呼应
C:\\ TEMP>如果定义你好回声定义
在第一种情况下的你好,你
已完成,但第二样品中的您
被放弃了。
Here's the example:
@echo off
:: check syntax ignores "^<delimiter>something" right after check expression
if defined path^ blah echo #
if exist c:\^ blah echo #
if errorlevel 0^ blah echo #
:: but in comparison operations escaping works well
if 1^ blah==1^ blah echo #
Why?
I don't know.
But It seems that the tokenizer executes two times in this cases.
Here is an example to show that the tokenizer is independent of the interim output of ECHO ON
echo ON
setlocal EnableDelayedExpansion
set "var=hello you"
if !var! == hello^ you echo true
if !var! == hello you echo true
Both lines are shown as if !var! == hello you echo true
but only the first executes the echo true
, as there hello you
is one token but not in the second sample.
set var=1
IF defined var^ bang echo VAR is defined
But as dbenham explains, the IF DEFINED
and the If EXIST
seems to tokenize it first as expected, as the second word will not be used as a command, but it's completly dropped.
The interessting effect is that a FOR parameter and delayed expansion aren't affected, although these phases are following directly the echo phase.
So I assume, that there is used another tokenizer by IF defined
and IF EXIST
in contrast to IF .. <compare>
.
With ECHO ON
(as JosefZ mentioned) you can see the differences.
if !var! == hello^ you echo true
if defined hello^ you echo is defined
Output
C:\temp>if !var! == hello you echo true
C:\temp>if defined hello echo is defined
In the first case the hello you
is complete, but in the second sample the you
was dropped.
这篇关于为什么如果检查搭理&QUOT; ^&LT; delimter&GT; some_word&QUOT;经过检查前pression?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!