I'm reluctantly learning to use Windows command prompt (Windows 10). I'm trying to make a batch file, and I've run into a bizarre problem that probably means I'm misunderstanding something basic about the syntax.
I've created a file called "test.bat" (a minimal example of the problem):
@echo off
set x=0
if %x%==0 (
set /p works="Type a thing: "
echo %works%
)
Here's what happens when I try to run it in a command prompt:
>test.bat
Type a thing: hi
ECHO is off.
>
>test.bat
Type a thing: ummm
hi
>
>test.bat
Type a thing: Why, just why
ummm
>
>test.bat
Type a thing: I hate u
Why, just why
>
It appears to be setting the PREVIOUSLY entered user input to the variable "works". If I remove the if
statement, the set
statement appears to work correctly as expected.
Ok, as I'm typing this, I think I've realized that IF statements can only have one statement within the parentheses, so instead of executing the two commands in series, it's somehow combining them.
Is...is that really true? Are my only choices for emulating an "if block"
- using a mess of goto commands or
- this "batch subroutine" thing?
Thanks.