Adhil 1989
Adhil 1989

Reputation: 25

batch file exit automatically after typing "

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

Answers (2)

aschipfl
aschipfl

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

foxidrive
foxidrive

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

Related Questions