0

To the environment set-up I need to pass the for %aa parameter to the variable. It seems simple set myvar=%%d is not enough. I tried to do some external call to the converter, but I'm not pretty sure how to set-up it. I finished with more a less following solution. But definetly it is not what I expect. I expect to properly echo myvar showing the proper values a, b, c, d one by one, but I could see the last one only.

for %%a in (a,b,c,d) do (
  call :extractvar myvar %%a
  echo %myvar%
)

:extractvar <resvar> <invar> (
  set "%1"
  exit /b
)

h__
  • 761
  • 3
  • 12
  • 41
  • 2
    two issues: [delayed expansion](https://stackoverflow.com/questions/30282784/variables-are-not-behaving-as-expected/30284028#30284028) and in the subroutine, it should be `set "%1=%2"` (and a missing `goto :eof` to prevent falling into the subroutine after the `for`loop ends, but I guess you are aware of that) – Stephan Nov 03 '20 at 12:59
  • 1
    simplest solution: `for %%a in (a,b,c,d) do echo %%a`. If you need the variable for some reason: `setlocal enabledelayedexpansion`, `for %%a in (a,b,c,d) do (`, `set "myvar=%%a"`, `echo !myvar!`, `)` – Stephan Nov 03 '20 at 13:03

0 Answers0