bat file if then with enviromental variables

April 25, 2011 at 20:56:08
Specs: Windows 7
I am trying to work on just a basic response file to fool around with friends who are not computer savy at all. In this it asks them how they are doing and is sposed to respond based off of that but when they enter more than one word it messes up and says (last word of what they typed)==good is unexpected at this time. Here is the start to the code can anyone point out what is wrong?

Code Starts:

@echo off
Echo Hi my name is Eva
Echo Who are you?
Set /p name=
Echo Nice to meet you %name%
:condition
Echo So how are you doing %name%
Set /p condition=
If /i %condition%==Good goto good
If /i %condition%==Fine goto good
If /i %condition%==Well goto good
If /i %condition%==Great goto good
If /i %condition%==OK goto good
If /i %condition%==Fantastic goto good
If /i %condition%==awsome goto good
If /i %condition%==Amazing goto good
If not "%condition%"==good goto Vocab
Pause
Exit

:good
Echo I am glad you are doing %condition%
Pause
exit

:Vocab

Echo My voacab is not that large could you try again with a simple answer
Pause
cls
Goto condition

:Code ends


See More: bat file if then with enviromental variables

Report •


#1
April 26, 2011 at 04:30:10
oh and as a note i have tried quotes and duoble quotes and it still gives me the same (second word that was entered)==good was unexpected at this time

Report •

#2
April 26, 2011 at 08:44:13
Set /p condition=
set condition="%condition:"=%"
If /i %condition%=="Good" goto good
If /i %condition%=="Fine" goto good
If /i %condition%=="Well" goto good
Et cetera.

Unless you want to parse word by word. If that's the case, you'd have to use a FOR loop.

How To Ask Questions The Smart Way


Report •
Related Solutions


Ask Question