cmd - Understanding what happens with variables when I call one batch script from another (largely terminology/semantics specific)? -


i've been learning bit batch scripting , have spent time past few days creating different .bat files hone skills , gain further understanding how work , many things can used accomplish.

today, curious whether or not call on batch script another, created 2 batch scrips: test.bat , test2.bat. code each follows:

test.bat

@echo off cls title test.bat  set /p "_result=enter 'c' capture or 'd' deploy:"  call test2.bat %_result%  

test2.bat

if "~%1" == "c" goto :capture if "~%1" == "d" goto :deploy  :capture echo _result %_result% echo %1 echo in capture label!! goto :eof  :deploy echo _result %_result% echo %1 echo in deploy label!! goto :eof 

i have few questions related above code think largely have semantics, think me understand more happening in simple exercise.

question 1:

when pass _result variable test2.bat, _result variable considered parameter that's being passed test2.bat? in other words, proper in case passing parameter or, since variable, should i'm passing variable? or both?

i have attempted figure out on own, why i've included echo _result %_result% , echo %1 in code. both echo same response, assume okay refer either way, please correct me if i'm wrong.

question 2:

since appears (to current understanding of this) _result holds it's variable attribute , value when passed test2.bat, mean should considered global variable?

question 3:

i'm little confused why retains same value in test2.bat assigned in test.bat since 2 different files (especially if it's considered parameter once it's passed). test2.bat considered extension of sorts of test.bat in case? , therefore variables designated in test.bat active in test2.bat?

i hope questions make sense. please let me know if need clarify anything. thank help.

_result variable set in environment test.bat called in, , that's why test2.bat can access (and modify it), , why can echo _result after test.bat finished.

when call test2.bat %_result% passing in value of _result test2's first argument (read %1).

you can add setlocal @ start of test.bat environment variables when you're done.


Comments