Why does this not work
Moderator: DosItHelp
-
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
- Contact:
Why does this not work
set str=operation
if "%str%"==str echo.%str%
if "%str%"==str echo.%str%
Re: Why does this not work
Euhhh
set str=operation
if "%str%"=="str" echo.%str%
set str=operation
if "%str%"=="str" echo.%str%
Re: Why does this not work
Try this:
setlocal enabledelayedexpansion
set str=operation
if '!str!'=='str' echo. %str%
im no pro on this
setlocal enabledelayedexpansion
set str=operation
if '!str!'=='str' echo. %str%
im no pro on this
Re: Why does this not work
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
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Why does this not work
lol 3 people missed the obvious error.
Re: Why does this not work
☺
Which error did we miss ?
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. . .
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Why does this not work
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.
Is the same as:
if "operation"==str
Is the same as:
if "operation"==operation
Works, as would "%str%" obviously. This is what dbenham is talking about.
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.
Last edited by orange_batch on 10 Jun 2011 22:13, edited 1 time in total.
-
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
- Contact:
Re: Why does this not work
@orange_batch
Well I'll be god damned. Good observation
That is a first.
Well I'll be god damned. Good observation
That is a first.