Open shadichy opened 1 year ago
@daniel-sc
like
someFunc() {
aGlobalVar=1
local aLocalVar=1
}
should returns something like
:someFunc
set aGlobalVar=1
setlocal
set aLocalVar=1
endlocal
exit /b 0
@shadichy I see some problem with this approach (wrapping individual 'local' assignments with 'setlocal'/'endloacal'): When the variable is used in subsequent lines the value is gone - e.g. the following script
ECHO OFF
setlocal
set aLocalVar="hello"
echo "inside first setlocal: %aLocalVar%"
endlocal
echo "outside setlocal: %aLocalVar%"
setlocal
echo "inside second setlocal: %aLocalVar%"
endlocal
has the output
"inside first setlocal: "hello""
"outside setlocal: "
"inside second setlocal: "
And since 'local' and 'global' variables could occur in any order this is a problem - or did I miss something?
@daniel-sc that's how 'local' variables work :)
I think that when using local variables, any command that uses those vars should be wrapped inside setlocal
and endlocal
, and if any local var is returned globally, use something like this e.g:
endlocal & (
set "GlobalVar1=%LocalVar1%"
set "GlobalVar2=%LocalVar2%"
set "GlobalVar3=%LocalVar3%"
)
Yeah I understand. The point is, that a mere syntactically approach (as currently used) does not suffice to solve this. One would need to analyze all variables and their usages..
seems hard Seems Microsoft has done really great in confusing their customers :)
@shadichy could you provide some example input together with the expected output?