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 do I update the Windows date and time to automatic using Batch?
How to rename the filenames in the folder with the new file names from the .txt in batch [on hold]
Using xcopy to copy files from 2 directories to one directory
Get mapped local folder path with TFS in batch file
Scheduled Task Stopped suddenly
Batch timeout command fails in Windows 2012 R2 Standard in 1st loop iteration
I want to remove unknown string between two specific character from text file using windows command
Is it a best practice to change the current work directory in the batch file?
How To Delete Folder, Sub-folder and files Automatically X days older on a network shared Drive
Batch file and path to .exe from a program
Walk through directory structure and move files with certain extensions up one level
How to xcopy all folders starting with string in depth 1?
batch script for moving file to other location based on modified date older then 2 days
How do i pass arguments while running a bat file in Jenkins
How to find If Java is installed or not using batch file?
Pull svn code using bacth file windows

Categories

HOME
shell
cygwin
assembly
scikit-learn
jpa
wakanda
composite-primary-key
code-coverage
jax-ws
nstableheaderview
special-characters
teechart
vimdiff
android-securityexception
spring-social
screen-readers
entitymanager
powershell-v5.0
job-scheduling
null-pointer
production
connector
symbols
named-entity-recognition
systemtime
dynamically-generated
jquery-multiselect
ms-access-web-app
linked-data
winexe
jaws
failover
constexpr
aws-codecommit
fstream
catch-unit-test
vue-chartjs
getpixel
carriage-return
least-squares
batching
swagger-php
dm-script
recurrent-neural-network
chef-solo
odoo-website
placeholder
ovf
dbcontext
static-cast
azure-cli
boxing
oracleclient
redbeard-ios
xcode-server
async.js
tinkerpop3
simevents
aurora
dbamp
findfirst
jparsec
dynatree
microsoft-reporting
.bash-profile
doctype
eoferror
wso2greg
sha512
graphics2d
mirror
typeconverter
ms-access-2000
broadband
document-repository
delayed-execution
dbaccess
cosine-similarity
crowd
punycode
iso-prolog
encryption-asymmetric
angular-carousel
ss7
cancellation
malformedurlexception
jquery-slider
fpdi
getopt
multitasking
jammer
c++builder-xe5
unit-of-work
gpars
stacky
virtual-pc
jdb
winmain
mbeans
uipagecontrol
photolibrary
timertask
silent
rowlex
spread
mathematical-notation
dojo-dnd
sifr3
linfu-dynamicproxy
httpcookie
leader

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile