I would like to ask your help in a possibly simple situation (where the solution is yet unknown for me).
I am trying to provide a variable for the if command to make a bit more “dynamic” the code, but this fails for me with:
% was unexpected at this time.
Here is a simple example for that:
> for %i in (NEQ) do (if 1 %i 2 echo jo)
%i was unexpected at this time.
While the following works like charm:
>set oper=NEQ
>for %i in (NEQ) do (if 1 %oper% 2 echo works)
works
As I should stay in the for loop (and I get the actual operator from the for loop in the real code), I am really stuck how to solve it…
Tried to play with EnableDelayedExpansion as well, but !variable! instead of the operator is refused as well. Is there a way to submit the variable in a FOR loop for IF, without major modifications in the script?
No!
Because, the
IFstatement has it’s own parser and it expects some tokens already expanded at this parse phase.So it’s neither possible to expand the options nor the operator, nor
NOT.But it’s allowed to expand the values with delayed or FOR-variables.
The percent expansion works, as it is expanded before the
IFparser gets the line.If you really need to use variable operators, then you need to use a function.
EDIT:
And the special parser is also the cause, that it’s not possible to use here a
CALLexpansion for theIFstatement.Like this idea
This should expand to
IF 1 EQU 1 echo Works, but the combination ofCALLandIFfails always.