batch-file


windows batch file - IF with AND condition using command-line arguments with a multi-line body [duplicate]


i am new here so i'll try to be as good as i can.
So i am trying to make a RPG based on text-based MS-DOS, and i am going pretty well as i just saw that if the user puts an invalid input at set /p, like an empty answer (just pressing enter) or an answer which is not on the "IF", the batch just crashes, and I would like to fix that so it will be less crashy.
Here is one of the parts i'd like to fix:
#echo off
title "Wasteland Adventure"
color 0A
cls
:Menu
cls
echo.
echo.
echo Welcome to Wasteland Adventure
echo.
echo To start a new game, type NEW and press ENTER.
echo To see instructions for the game, type INSTRUCTIONS and press ENTER.
echo To quit, type QUIT and press ENTER.
set input=
set /p input=What do you want to do?
if %input%==new goto INTRO
if %input%==instructions goto INSTRUCTIONS
if %input%==quit goto EXIT
Thanks in advance
it's not the set /pthat crashes, but:
if %input%==new
if %input% is empty, this is parsed as:
if ==new
obviously a syntax error. To avoid this, use:
if "%input%"=="new"
An empty input will then be parsed as:
if ""=="new"
which works fine. Complete code like this:
:Menu
set input=
set /p input=What do you want to do?
if "%input%"=="new" goto INTRO
if "%input%"=="instructions" goto INSTRUCTIONS
if "%input%"=="quit" goto EXIT
REM for any other (invalid) input:
goto :Menu

Related Links

how to make file listing using the .bat script
Batch Files - Error Handling
batch for loop with bracket in the command
Set= log.txt in batch
XCOPY exclude list ignored after first exclusion
How to delete every n-th char in file (via batch or vbs)?
Batch Scripting, For using the results of a dir
How do I keep DOS batch echo on for parent script?
Batch file: Password Stars/Circles
[NT Batch]How to get directory from user inputted file?
Passing result of one batch file to another?
Deleting a directory (sub-directpries)using batch program on a event of new directory creation
Batch file fails to set environment variable within conditional statement
Batch rename/copy/delete not working?
Batch file FOR/f expansion
Ignore question mark in .bat batch scripts

Categories

HOME
oracle12c
adal
checkstyle
youtube-data-api-v3
pascal
composite-primary-key
alarm
rds
dojo
hugo
mapbox
arangodb
internationalization
symfony-console
charles
database-connection
selinux
asciidoctor-pdf
guzzle
ksh
cgbitmapcontext
string-concatenation
exploit
xunit
game-theory
fat
custom-post-type
angular-translate
sqsh
complex-numbers
weather
keras-layer
installscript
least-squares
reason
railstutorial.org
p4merge
chef-solo
setup.py
logback-groovy
lpsolve
outputcache
jboss-4.2.x
manova
pair-programming
context-sensitive-grammar
edit
android-testing
filehandle
mouseleave
cpu-cache
rxtx
docpad
latin
preprocessor
file-uri
jquery-jscrollpane
avspeechsynthesizer
shopping
bizagi
toast
phpgrid
decimalformat
coda
.bash-profile
finalbuilder
viola-jones
dronekit-android
liquid-layout
apache-commons-daemon
nsurlsessiondatatask
aspectj-maven-plugin
uvc
filesplitting
rmysql
gii
cancellation
ecslidingviewcontroller
scriptaculous
model-driven-development
gpars
stacky
chart-director
robotlegs
fusefabric
node-redis
pinch
expression-blend-4
android-holo-everywhere
ie-compatibility-mode
easyb
binomial-heap
pos-for-.net
fail-fast-fail-early
unmanagedresources

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App