I'm trying to make Windows prompt set a default value to a variable as a result of if operator.
I took the following code as a model:
(echo "getter" | find "ette") >nul && set "err=1" || set "err=0" & echo %err%
:: Outputs 1 after calling repeatedly, which shows it found ette substring
(echo "getter" | find "gh") >nul && set "err=1" || set "err=0" & echo %err%
:: Outputs 0 after calling repeatedly, which shows it failed to find gh substring
The above code works perfectly, showing some output each time it is called despite the fact the substring which is looked for has not been found. So I want to make the following code print output:
if %appdata% == %^appdata% (echo theVarUndefined) | find "theVarUndefined" >nul && set "err=1" || set "err=0" & echo %err%
However, it prints nothing!
It works only for undefined environment variables:
if %undefinedVar% == %^undefinedVar% (echo theVarUndefined) | find "theVarUndefined" >nul && set "err=1" || set "err=0" & echo %err%
The above code prints 1.
The question: how can I make if %appdata% == %^appdata% (echo theVarUndefined) | find "theVarUndefined" >nul && set "err=1" || set "err=0" & echo %err%
print default value in case the find
command didn't find anything?