为什么如果检查搭理" ^< delimter> some_word"经过检查前pression? [英] Why IF checking ignores "^<delimter>some_word" after the check expression?

查看:208
本文介绍了为什么如果检查搭理" ^< delimter> some_word"经过检查前pression?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的例子:

 关闭@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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆