Dos - How to check Variable Name exist based on user Input? -


i have below batch code , want check when user type e.g. sb1 input, sb1 varialbe name exist. in case exist. if user type sx1 not exit.

@echo off set "sb1=hannlsb1.mydomain.com:30515 -i 05" set "db1=hannlsd2.mydomain.com:31315    -i 13" set "qb1=hannlsqa1-1:30115 -i 01" set "db0=hannlsd1.mydomain.com  -i 10" set "qb0=hannlsps1-1.mydomain.com-i 03" set "wb1=hannlsqa1-1:30315 -i 03" set "vb1=hannlsvt-1.mydomain.com    -i 01"   @echo off set /p sysid=please enter systemid: if "%sysid%"=="" goto error rem echo hello %sysid%, welcome dos inputs! goto end :error echo did not enter system id! bye bye!! :end 

here's 1 way using for /f run echo command expands sysid value in middle of expression expands value again.

@echo off set "sb1=hannlsb1.mydomain.com:30515 -i 05" set "db1=hannlsd2.mydomain.com:31315    -i 13" set "qb1=hannlsqa1-1:30115 -i 01" set "db0=hannlsd1.mydomain.com  -i 10" set "qb0=hannlsps1-1.mydomain.com-i 03" set "wb1=hannlsqa1-1:30315 -i 03" set "vb1=hannlsvt-1.mydomain.com    -i 01"  setlocal enabledelayedexpansion set /p sysid=please enter systemid: /f "usebackq delims==" %%i in (`echo+!%sysid%!`) set val=%%i setlocal disabledelayedexpansion if not "%val%"=="" (    echo hello %sysid%, welcome dos inputs! ) else (    echo did not enter system id! bye bye!! ) 

note delayed expansion has unfortunate side-effect cannot include exclamation marks in echo commands while enabled.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -