DOS批处理:SET变量并在(...)块内回显它 [英] DOS batch: SET variable and ECHO it within (...) block
本文介绍了DOS批处理:SET变量并在(...)块内回显它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对 set
不能在批处理文件中工作有问题;解决这个问题花了一段时间;起初我以为这与子程序调用有关……
I had a problem with set
not working in a batch file; it took a while to distil the problem; at first I thought it was to do with subroutine calls...
脚本
@echo off
setlocal
set a=aaa
echo a = "%a%"
(
set b=bbb
echo b = "%b%"
)
产生输出
a = "aaa"
b = ""
我期望
a = "aaa"
b = "bbb"
请问为什么?是DOS中的错误吗?也许我不知道关于(...)
命令分组语法的某些事情.
Why is this please? Is it a bug in DOS? Perhaps there's something about the (...)
command grouping syntax that I'm unaware of.
谢谢.
推荐答案
用户延迟了扩展,!代替%
User delayed expansion and ! instead of %
@echo off
setlocal enableextensions enabledelayedexpansion
set a=aaa
echo a = "%a%"
(
set b=bbb
echo b = "!b!"
)
这篇关于DOS批处理:SET变量并在(...)块内回显它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文