Batch file 如何批量更改变量
所以我在批处理变量时遇到了这个问题,我似乎无法更改变量Batch file 如何批量更改变量,batch-file,variables,login,Batch File,Variables,Login,所以我在批处理变量时遇到了这个问题,我似乎无法更改变量 @echo on title Login color a :begin cls echo ------------------------------------------------------------ echo. echo Login echo. echo --------------------------------------------------------
@echo on
title Login
color a
:begin
cls
echo ------------------------------------------------------------
echo.
echo Login
echo.
echo ------------------------------------------------------------
::This is 2 person chat system
set Username1=Jush
set Username2=Test
set User=
set UP1=password
set UP2=Test
set /p input_u=Username:
set /p input_p=Password:
if {%input_u%}=={%Username1%} goto :User1_p
if {%input_p%}=={%Username2%} goto :User2_p
echo Incorrect Username
pause
goto :begin
:User1_p
%User%=Jush
if {%input_p%}=={%UP1%} goto :Server
echo Incorrect Password!
%User%=
goto :begin
:User2_p
%Use%=Test
if {%input_p%}=={%UP2%} goto :Server
echo Incorrect Password!
%User%=
goto :begin
:Server
pause
echo Welcome %User%
pause
然后它会出现一个错误:'Jush'未被识别为内部或外部命令,
可操作的程序或批处理文件。“
我错过什么了吗?这里
if {%input_p%}=={%Username2%} goto :User2_p
应该是
if "%input_p%"=="%Username2%" goto :User2_p
SET User=Jush
因为批处理将匹配引号之间的两个sring,而不考虑空格等分隔符。{
和}
对批处理没有特殊意义
%User%=Jush
应该是
if "%input_p%"=="%Username2%" goto :User2_p
SET User=Jush
或者最好
SET "User=Jush"
这可确保未将尾随空格指定给变量
您的原始代码将尝试执行jush
作为user
内容的代码
jush=Jush
这将尝试执行一个名为jush的呃可执行文件,我能够修复一些东西 示例:
@echo off
set /p input_name=What is your name:
set name=%input_name%
echo Hello, %name%
pause
输入:日文
输出:您好,Jush您在批处理的开始处设置了
用户=
,因此行%User%=Jush
将计算为=Jush
,这将给出此错误消息。您的意思是设置用户=Jush
?