0

I am unable to set the variables inside if else.

@echo off
set cur_date=check
echo %cur_date%     

if "true"=="true" (
  echo 1
  set curs_date=checks
  echo %curs_date%
)
pause

In above code, echo %cur_date% and echo 1 are getting printed.
But echo %curs_date% is not assigned.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
Sid ABS
  • 59
  • 1
  • 11
  • 4
    you need [delayed expansion](http://stackoverflow.com/a/30284028/2152082) (by the way: your variable _is_ set but not shown.) – Stephan Nov 21 '15 at 09:42

1 Answers1

1

You should use Setlocal EnableDelayedExpansion at the top of your script, and inside the if statement use ! instead of %. See also this or this

Community
  • 1
  • 1
Dennis van Gils
  • 3,487
  • 2
  • 14
  • 35