Page 1 of 1
Why does this not work
Posted: 07 Jun 2011 23:22
by Cleptography
set str=operation
if "%str%"==str echo.%str%
Re: Why does this not work
Posted: 07 Jun 2011 23:25
by Ed Dyreen
Euhhh
set str=operation
if "%str%"=="str" echo.%str%
Re: Why does this not work
Posted: 08 Jun 2011 01:02
by renzlo
Try this:
setlocal enabledelayedexpansion
set str=operation
if '!str!'=='str' echo. %str%
im no pro on this
Re: Why does this not work
Posted: 08 Jun 2011 05:34
by dbenham
Cleptography wrote:set str=operation
if "%str%"==str echo.%str%
What is not working
Nothing happens as expected.
"operation" <> str so echo does not fire.
Dave Benham
Re: Why does this not work
Posted: 10 Jun 2011 06:26
by orange_batch
lol 3 people missed the obvious error.
Re: Why does this not work
Posted: 10 Jun 2011 06:33
by Ed Dyreen
☺
Which error did we miss ?
Code: Select all
@echo off
echo.errorlevel=%errorlevel%
set str=operation
if "%str%"==str echo.%str%
echo.errorlevel=%errorlevel%
pause
exit
Code: Select all
errorlevel=0
errorlevel=0
Druk op een toets om door te gaan. . .
Re: Why does this not work
Posted: 10 Jun 2011 16:02
by orange_batch
Not error levels. Bad syntax.
Batch is interpreted as text, there's no literal or non-literal working with variables with the exception of set /a expressions. Quotations exist as regular characters too, the only difference being they toggle DOS's interpretation of special characters.
Code: Select all
set str=operation
if "%str%"==str echo.%str%
Is the same as:
if "operation"==str
Code: Select all
set str=operation
if "%str%"==%str% echo.%str%
Is the same as:
if "operation"==operation
Code: Select all
set str=operation
if "%str%"=="operation" echo.%str%
Works, as would "%str%" obviously. This is what dbenham is talking about.
Re: Why does this not work
Posted: 10 Jun 2011 18:39
by Cleptography
@orange_batch
Well I'll be god damned. Good observation
That is a first.