Batch File if giving unexpected results/weird logic
Ok, so I'm not sure whats going on here. I'm hoping it will be obvious to a second set of eyes. I'm performing an If statement and getting the same results no matter what...
if \%3\==\\ (set filter=FullExclude.开发者_C百科txt) else (set filter=%3)
if %filter%==%3 (set output = CustomDiffData) else (set output = USERDATA)
echo %output%
parameter 3 is being entered at custom.txt
so the first if there should be false and filter is set to custom.txt this is confirmed with an echo.
Next if should be true because custom.txt = custom.txt...this is where things get weird because output echos back USERDATA even weirder if i do this:
if %filter%==%3 (set output = USERDATA) else (set output = CustomDiffData)
echo %output%
I still get USERDATA echoed back.
Any ideas why this is?
this is at the very top of my script minus two null param checks that just end script.
The main problem is the set output =...
you use a variable named output<space>
not output
.
You should avoid (unneccessary) spaces in batch files.
Another porblem could be in the line if \%3\==\\
, as %3 could contain spaces or special characters this would fail with an batch error.
It's better to use quotes like
if "%~3"=="" (set filter=FullExclude.txt) else (set "filter=%~3")
And to avoid the second compare you could change your code to
if "%~3"=="" (
set filter=FullExclude.txt
set output=USERDATA
) else (
set "filter=%~3"
set output=CustomDiffData
)
echo %output%
精彩评论