Solved Why does this batch file keep crashing?

September 14, 2017 at 11:36:22
Specs: Windows 10, N2930 1.83GHz / 8 gigs
I have this batch script that extracts data from a text file in "batch file directory"/userdata. and uses it as a username and password. However, I want to have an exception in the rule. If the user types "root" at the "username" prompt, it should take them to :bash.
But for some reason when I type "root" it just reads:

"root" was unexpected at this time.
and goes back to cmd.

Script:
:login
echo Sign in.
set /p user=username:
if user=root goto bash
set /p pass=password:
cd userdata
set /p password=<%user%.txt
cd..
if %pass% equ %password% goto pbash
goto login


See More: Why does this batch file keep crashing?

Reply ↓  Report •

#1
September 14, 2017 at 22:26:17
✔ Best Answer
Problem here:
"if user=root goto bash"

You need to test for the VALUE of the var, like you do with pass.

if "%user%"=="root" goto bash
[note the double =]
or
if "%user%" equ "root" goto bash

=====================

M2 Get custom script or take private lessons

message edited by Mechanix2Go


Reply ↓  Report •
Related Solutions


Ask Question