|  | 
| 本帖最后由 liangzr1976 于 2025-4-29 06:57 编辑 
 
   这个图注,看看是否可以参考理解。
 
 测试时,一定要多关闭 CMD窗口。
 
 前面正确语句 生成的 结果,容易影响后面的判断,
 实在不好清除 或关闭,至少用 set input = ""    或 set input =  来标识 或 清除变量值。
 
 1、我的理解是 set /p input= 这个语句,回车后,由于语句本身 没有加入 提示文字,应该是提示文字为空字符串。
 然后楼主输入的 %temp%\00.log,会整个作为字符串识别,而不会将 %temp%作为变量展开。
 
 2、但如果 直接   set  input=  %temp%\00.log 再回车,这个时候变量 不作为键盘输入,可直接解释为变量。
 3、语句只会展开一次 变量,不可能反复展开嵌套的变量,
 比如 input = %temp%\0000.log
 echo %input%,能展开1次变量 ,是正确的
 但 dir %input%,展开的 结果 实际是 dir “%temp%\0000.log”,只是显示为 dir %temp%\0000.log。这里面嵌套的 %temp% 不会二次展开变量值
 
 ===============================
 Microsoft Windows [版本 10.0.19044.2364]
 (c) Microsoft Corporation。保留所有权利。
 
 C:\Users\Administrator>set /o input
 命令语法不正确。
 
 C:\Users\Administrator>set /o input=
 命令语法不正确。
 
 C:\Users\Administrator>set /p input=
 %temp%\0000.log
 
 C:\Users\Administrator>%temp%\0000.log
 'C:\Users\ADMINI~1\AppData\Local\Temp\0000.log' 不是内部或外部命令,也不是可运行的程序
 或批处理文件。
 
 C:\Users\Administrator>help > %input%
 系统找不到指定的路径。
 
 C:\Users\Administrator>help >"%input%"
 系统找不到指定的路径。
 
 C:\Users\Administrator>%input%
 系统找不到指定的路径。
 C:\>md tmp
 
 C:\>cd tmp
 
 C:\tmp>dir %input%
 系统找不到指定的文件。
 
 C:\tmp>dir &input
 驱动器 C 中的卷是 w7BFSSD
 卷的序列号是 DA18-EBFA
 
 C:\tmp 的目录
 
 2025/04/29  06:34    <DIR>          .
 2025/04/29  06:34    <DIR>          ..
 0 个文件              0 字节
 2 个目录 17,800,982,528 可用字节
 'input' 不是内部或外部命令,也不是可运行的程序
 或批处理文件。
 
 C:\tmp>dir &input%
 驱动器 C 中的卷是 w7BFSSD
 卷的序列号是 DA18-EBFA
 
 C:\tmp 的目录
 
 2025/04/29  06:34    <DIR>          .
 2025/04/29  06:34    <DIR>          ..
 0 个文件              0 字节
 2 个目录 17,800,982,528 可用字节
 'input%' 不是内部或外部命令,也不是可运行的程序
 或批处理文件。
 
 
 C:\tmp>echo %input%
 %temp%\0123.log
 C:\tmp>dir & cd ..
 驱动器 C 中的卷是 w7BFSSD
 卷的序列号是 DA18-EBFA
 
 C:\tmp 的目录
 
 2025/04/29  06:34    <DIR>          .
 2025/04/29  06:34    <DIR>          ..
 0 个文件              0 字节
 2 个目录 17,789,014,016 可用字节
 C:\>
 ====================================
 
 
 
 
 
 
 
 
 
 | 
 |