我通过for把文件内容赋值给不同的变量,但是几个menu切换以后,数据就重复了,就显示2个一样的sn,重现方法:菜单1-》菜单1返回
1.txt的内容如下
List of devices attached
c003 device- @echo off
- :getsn
- setlocal enabledelayedexpansion
- #获取手机的sn并赋值给变量,可以有多个手机
- FOR /F "skip=1 tokens=1 delims= " %%i in (1.txt) do (
- if not defined d1 (set d1=%%i) else (
- if not defined d2 (set d2=%%i))
- )
- ::取出设备信息的sn
- FOR /F "usebackq tokens=1 delims= " %%a in ('%d1%') do set device1=%%a
- FOR /F "usebackq tokens=1 delims= " %%i in ('%d2%') do set device2=%%i
-
- :startsn
- cls
- echo =============请选择sn =============
- echo 1.%device1%
- echo.
- echo 2.%device2%
- echo ==========================================
- set /p startsn1=你的选择是(输入序号):
- if %startsn1% ==1 (
- set startsn=%device1%
- goto menu
- )
-
- if %startsn1%==2 (
- set startsn=%device2%
- goto menu
- )
- :menu
- cls
- echo =============请选择 ==============
- echo 1.返回上一级 2.开始
- echo ===========================
- set /p user_input=选择(输入序号):
- if %user_input% ==1 goto getsn
- if %user_input%==2 goto :run
-
- :run
- echo start test
- pause
复制代码
|