batch if neq several words

December 12, 2010 at 01:23:52
Specs: Windows 7
Hi
Im trying to make sort of a batch dialogue
I just need to know:
is it possible to use more than one (unspecified) word when using
if %answer% NEQ "blabla"

here is the section:
:q1
echo What's up?
set /p sup=
cls
if %sup%=="nm" goto nm
if %sup%=="not much" goto nm
if %sup%=="nothing" goto nm
if %sup%=="nothin" goto nm
if %sup% neq "nm" goto shh
if %sup% neq "not much" goto shh
if %sup% neq "nothing" goto shh
if %sup% neq "nothin" goto shh

It worked as it should when entering single words, but when entering more it just shut down


See More: batch if neq several words

Report •


#1
December 12, 2010 at 04:47:06
I'm surprised it even worked with a single word. It should be

if "%sup%" neq "not much" goto shh

Otherwise you are comparing a quoted string with a non-quoted one, and they will compare as different.

By the way, why are you doing this? You don't need all the neq comparisons.


Report •

#2
December 12, 2010 at 08:06:33
what you recommend then?

Report •

#3
December 12, 2010 at 13:31:38
So you have

if "%s%" == "a" goto nm
if "%s%" == "b" goto nm
if "%s%" == "c" goto nm
by the time you get past these three lines, you already know that "%s%" is neither "a" nor "b" nor "c", so why test them again?

In other words, you know that every one of the following three statements

if "%s%" neq "a" ...
if "%s%" neq "b" ...
if "%s%" neq "c" ...

will equate to true, so these if statements are completely redundant.


Report •

Related Solutions

#4
December 12, 2010 at 14:51:20
well.. the point was that i needed the neq to lead to another path
i did, however delete all except one of them
thx for the advice ;)
now, to the question i actually asked.. is there a way for several words to work with the if %x% neq y goto z
using the the section i wrote above: how can i make the answer to "whats up?" be a whole sentence and still work with the [if %x% neq y goto z] command, and not just shut it down?
(example:
[question {echo}]"whats up?"
[answer] "Im just hanging around")

Report •

#5
December 13, 2010 at 17:47:18
Same as what I said before:

if "%sup%" neq "not much" goto shh

I.e. you can put as many words as you like between quotes.


Report •

#6
December 14, 2010 at 08:45:25
it aint working

Report •

#7
December 14, 2010 at 10:54:37
and you've definitely got the quotes around "%sup%" too?

Report •

#8
December 14, 2010 at 10:57:51
now it worked..
thx :D
and yes.. i had the ""s
think it was n misspelling or something i must have corrected while working on other stuff

Report •


Ask Question