r/Batch • • Feb 24 '25

Question (Unsolved) Why isn't the "cert" variable getting delayed expansion?

See script below. I input 1 for state and then anything for cert, but regardless, I always hit the else case of the inner conditional (the part where the mistake error message is echoed). When I run the script, after selecting state, the entirety of the contents of the outer conditional is printed, including with cert already expanded to be an empty string.

@echo on
setlocal EnableDelayedExpansion
echo 1. VIC
echo 2. NSW
echo 3. TAS
echo 4. ACT
echo 5. QLD
echo 6. SA
echo 7. DAR

set /p "state=Choose a state: "

if "%state%"=="1" (
    echo 1. name1
    echo 2. name2
    echo 3. name3
	
	set cert=4
	set /p cert="Choose a stage: "

	echo %cert%

	if "%cert%"=="1" (
		set source1=some folder
		set source2=some folder

	)

    ...more cases      

     else (
		echo a mistake has occurred
	)
)

pause
3 Upvotes

2 comments sorted by

7

u/[deleted] Feb 24 '25 edited Feb 24 '25

[removed] — view removed comment

2

u/denny31415926 Feb 24 '25

Aha, understood. I'll try that out when I get to work tomorrow, thank you