我需要一些帮助。 这段代码
for /f "usebackq delims=" %%a in (`
mysql -u%dbUser% -e "SHOW DATABASES LIKE '%%sample%%';"
^| findstr /l /v /c:"Database" /c:"information_schema"
`) do set a=%%a
如果 echo %% a ,会产生结果
sample
sample_test
test_sample
但是当我添加 echo%a%时,使用该代码进行for循环 结果只是
test_sample
怎么可能这样我仍然可以在 echo %% a
上获得相同的输出答案 0 :(得分:2)
setlocal enableDelayedExpansion
for /f "usebackq delims=" %%a in (`
mysql -u%dbUser% -e "SHOW DATABASES LIKE '%%sample%%';"
^| findstr /l /v /c:"Database" /c:"information_schema"
`) do (
set "a=!a! %%a"
echo !a!
)
echo %a%
答案 1 :(得分:1)
这就是诀窍:
@echo off
setlocal EnableDelayedExpansion
set LF=^
%empty line%
%empty line%
for /f "usebackq delims=" %%a in (`
mysql -u%dbUser% -e "SHOW DATABASES LIKE '%%sample%%';"
^| findstr /l /v /c:"Database" /c:"information_schema"
`) do set "a=!a!%%a!LF!"
echo !a!