在IF转义字符 [英] escape character in IF
本文介绍了在IF转义字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想这在不同的变化(如SETLOCAL EnableDelayedExpansion) - 但没有作品:
ECHO OFF
IF%1==调试^ | Win32的设置servicesConfig = Win2008.Debug
回声不正确的parametr%servicesConfig%
暂停> NUL
解决方案
由于引号转义特殊字符,你比较%1
与内容调试^ |的Win32
(包括尖号)
在你的情况,你应该使用
关闭@echo
IF%〜1==调试|的Win32(
呼应这没关系
设置servicesConfig = Win2008.Debug
)ELSE(
在回声未知%〜1
)
您可以把它叫做
test.bat的调试|的Win32
要么
test.bat的调试^ |的Win32
的%〜1
将用引号括起来的第一个参数,这样特殊的字符是无害的,但如果第一个参数是已经引用了%〜
将添加新的报价前,剥夺他们,所以你总是只有一个封闭的。
i tried this in different variations (like setlocal EnableDelayedExpansion)- but nothing works:
echo off
IF "%1"=="Debug^|Win32" set servicesConfig=Win2008.Debug
echo Incorrect parametr %servicesConfig%
pause > nul
解决方案
As quotes escapes special characters you compare the content of %1
with Debug^|Win32
(including the caret).
In your case you should use this
@echo off
IF "%~1"=="Debug|Win32" (
echo It's ok
set servicesConfig=Win2008.Debug
) ELSE (
echo Unknown in "%~1"
)
You can call it with
test.bat "Debug|Win32"
or
test.bat Debug^|Win32
The "%~1"
will enclose the first parameter in quotes, so special charaters are harmless, but if the first parameter is already quoted the %~
will strip them before adding the new quotes, so you always get only one enclosing.
这篇关于在IF转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文