Reputation: 25
I have created a batch file as below
@echo off
echo Type Below Requirements:
echo.
:username
set /p usr= Type Username:
if %usr%==[%1]==[] goto username
echo Your username is: %usr%
pause
This is working perfectly when I am typing any text, but if I type " batch is Exit Automatically.
Upvotes: 0
Views: 94
Reputation: 34979
Firstly, the comparison expression syntax if %usr%==[%1]==[]
is wrong, it should read if [%usr%]==[]
instead.
Secondly, to handle double-quotes correctly, you will need to enable delayed expansion.
The following should work:
@echo off
setlocal EnableDelayedExpansion
echo Type Below Requirements:
echo.
:username
set usr=
set /p usr= Type Username:
if [!usr!]==[] goto username
echo Your username is: !usr!
pause
Upvotes: 0
Reputation: 41287
Here is another way:
@echo off
echo Type Below Requirements:
echo.
:username
set "usr="
set /p "usr= Type Username: "
if not defined usr goto :username
echo Your username is: %usr%
pause
Upvotes: 2