windows - Print variable in batch file -


i trying print variable in parenthesised code assigned value using other variable in batch file.

here code

@echo off setlocal enabledelayedexpansion call initialize call fun :fun (  @echo off  setlocal enabledelayedexpansion  set "somevar=!othervar!"  echo ..%somevar%  exit /b 0 ) :initialize (  set somevar=somevalue exit /b 0 ) 

the output

.. 

how fix can assign value somevar?

edit1: if try print in following way job

echo ..!somevar! 

but script uses lot of %somevar%. mean need change them all?

note: othervar initialzed in other function , show proper value if echoed.

since code portion containing echo %somevar% in between parenthesis, variable expanded before being set (consult this post explanation).

there following options avoid that:

  1. to expand !somevar! (delayed expansion), or
  2. to avoid parenthesis:

    @echo off setlocal enabledelayedexpansion call initialize call fun exit /b  :fun setlocal enabledelayedexpansion set "somevar=!othervar!" echo ..%somevar% exit /b 0  :initialize set somevar=somevalue exit /b 0 

    note additional exit /b in above code snippet after call statements, prevents falling code below unintentionally.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -