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:
- to expand
!somevar!(delayed expansion), or 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 0note additional
exit /bin above code snippet aftercallstatements, prevents falling code below unintentionally.
Comments
Post a Comment