My gosh Ed, can't you just solve it properly? lol
Plank, the problem is because you are trying to use regular variable expansion within parentheses. Command Prompt expands variables within parentheses at the time it READS the code. There's two ways around this, either using a call to delay that expansion or enabling delayed expansion and using the ! ! syntax to expand the variable at execution time.
In your code, you are testing the variable right away within parentheses though, so you have to use ! ! syntax because call only works with commands like set and echo.
Here is your modified code with some minor fixes:
Code: Select all
@echo off&setlocal enabledelayedexpansion
set CURRENTVERSION=10_03_00_136
set SIGFILE="%windir%\Deploy\Salto.sig"
set VERSION=X
IF NOT EXIST %SIGFILE% (
call :Install
exit /b
) ELSE (
for /f "usebackq" %%a in (%SIGFILE%) do (
echo "%%a"
set "VERSION=%%a"
echo "VERSION AFTER !VERSION!"
)
IF "!VERSION!"=="%CURRENTVERSION%" (
EXIT /b
) ELSE (
ECHO INSTALL
exit /b
)
)
If you need to preserve exclamation marks, you need to use enabledelayedexpansion carefully... best done using a flag. The logic behind this is slightly advanced.
Code: Select all
@echo off
set CURRENTVERSION=10_03_00_136
set SIGFILE="%windir%\Deploy\Salto.sig"
set VERSION=X
IF NOT EXIST %SIGFILE% (
call :Install
exit /b
) ELSE (
setlocal enabledelayedexpansion&set delayed=on
for /f "usebackq" %%a in (%SIGFILE%) do (
echo "%%a"
set "VERSION=%%a"
echo "VERSION AFTER !VERSION!"
)
IF "!VERSION!"=="%CURRENTVERSION%" (
EXIT /b
) ELSE (
if defined delayed endlocal
ECHO INSTALL
exit /b
)
if defined delayed endlocal
)