|
Answer» hi
i just ry to create dos menue with numbers
example
make your choice 1) .... 2) .... 3) .....
my batchfile wait for userinput.
I try to use if statement
if "%userinp%"=="1" SET test=beer goto start
But something is wrong in the line. What i want is if User INPUT is number 1 the batch should set VALUE of variable test to beer and subsequently goto label start.
Thanks for help knezeNormally you can only have one command on a line, and only one command after an IF statement (to be executed if the IF test evaluates to "true"). If you want to do more than one thing after an IF you can either use the & command separator or use brackets to create a block.
if "%userinp%"=="1" SET test=beer & goto start
if "%userinp%"=="1" ( SET test=beer goto start )
You will have observed that in your ORIGINAL CODE, "%test%" is equal to "beer goto start".
This is because the set command takes everything from the = SIGN to either an & or the end of the line.
This is why I need to make a correction to my above code.
this line:
set test=beer & goto start
will result in "%test%" being equal to "beer " with a trailing space.
You can avoid this either by:
(a) using quotes thus:
set "test=beer" & goto start
or...
(b) by leaving no space before the & thus:
set test=beer& goto start
|