1

I need some help. This code

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

has a result if echo %%a

 sample
 sample_test
 test_sample

but after the for loop with that code when i add echo %a% the result is only

 test_sample

how could it be so that i can still get the same output on echo %%a

1
  • So, from the previous question, that concatenates the databases names in the variable, if i understand you, what you need is to store a line feed between the names. Is this right? Commented Feb 12, 2015 at 7:31

2 Answers 2

1

This do the trick:

@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!
Sign up to request clarification or add additional context in comments.

Comments

1

you need a delayed expansion

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%

4 Comments

i already did that sir. what i want is when i add another code echo !a! outside the for loop . the output is only test_sample wherein i want to display sample sample_test test_sample same as !a! within the for loop.
@xXxrk04 - so you want to append the result to %a%?
the result of !a! is sample sample_test test_sample and the result of %a% is only test_sample .. i want %a% has the same output with !a!
@xXxrk04 - not sure what you mean.The last echo %a% should contain all lines....?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.