I think the easiest would be to simply create a for loop and test each value. So consider the following:
If you want to do nothing if a value is empty (undefined), and simply use the variable's value, which are defined:
@echo off
set "test1=Value1"
set "test2=Value2"
set "test3="
set "test4=Value4"
set "myvars=%test1% %test2% %test3% %test4%"
for %%i in (%myvars%) do echo %%i
If you actually want to only test if a variable is undefined or not:
@echo off
set "test1=Value1"
set "test2=Value2"
set "test3="
set "test4=Value4"
set "myvars=test1 test2 test3 test4"
for %%i in (%myvars%) do if not defined %%i (echo %%i not defined) else echo %%i Defined
or if you simply want to rather include the variables in the loop and not assign them to a single variable:
@echo off
set "test1=Value1"
set "test2=Value2"
set "test3="
set "test4=Value4"
for %%i in (test1 test2 test3 test4) do if not defined %%i (echo %%i not defined) else echo %%i Defined
If Not Defined TEST Echo TEST is not defined. In the example above by Gerhard, you don't need anif, because only defined variables would be passed from theForset, in the parentheses.for %%i in (%var1% %var2% %var3%) do echo %%ito only echo variables that are defined, as mentioned by @Compo . I deleted original comment to repost and removeif