是永远不能出现在用户定义的批处理环境变量名是=
唯一的字符。 SET语句将在第一次出现=
时终止一个变量名称,之后的所有内容都将成为该值的一部分。
指定包含:
的变量名很简单,但通常情况下,除特定情况外,不能展开该值。
当扩展名被启用(默认行为)
结肠是搜索的一部分/替换和子串扩展语法,这与含有在名称结肠变量膨胀干涉。
有一个例外 - 如果:
显示为名称中的最后一个字符,那么该变量可以扩展得很好,但是不能对该值执行搜索和替换或子字符串扩展操作。
当扩展是禁用
查找/替换和子扩张是不可用的,所以没有什么从工作得很好停止含冒号变量的扩张。
@echo off
setlocal enableExtensions
set "test:=[value of test:]"
set "test:more=[value of test:more]"
set "test"
echo(
echo With extensions enabled
echo -------------------------
echo %%test:%% = %test:%
echo %%test::test=replace%% = %test::test=replace%
echo %%test::~0,4%% = %test::~0,4%
echo %%test:more%% = %test:more%
setlocal disableExtensions
echo(
echo With extensions disabled
echo -------------------------
echo %%test:%% = %test:%
echo %%test:more%% = %test:more%
--OUTPUT--
test:=[value of test:]
test:more=[value of test:more]
With extensions enabled
-------------------------
%test:% = [value of test:]
%test::test=replace% = :test=replace
%test::~0,4% = :~0,4
%test:more% = more
With extensions disabled
-------------------------
%test:% = [value of test:]
%test:more% = [value of test:more]
的扩张究竟是如何工作的变量的完整说明,请参见https://stackoverflow.com/a/7970912/1012053。
当然,完全滑了我的脑海。谢谢。 – unclemeat
+1,不完全是整个故事,但接近;)请参阅[我的回答](http://stackoverflow.com/a/22159812/1012053) – dbenham