Windows Batch Files: if else

前端 未结 6 837
执笔经年
执笔经年 2020-12-24 00:42

I\'m doing a simple batch file that requires one argument (you can provide more, but I ignore them).

For testing, this is what I have so far.

if not          


        
6条回答
  •  爱一瞬间的悲伤
    2020-12-24 01:12

    Surround your %1 with something.

    Eg:

    if not "%1" == ""
    

    Another one I've seen fairly often:

    if not {%1} == {}
    

    And so on...

    The problem, as you can likely guess, is that the %1 is literally replaced with emptiness. It is not 'an empty string' it is actually a blank spot in your source file at that point.

    Then after the replacement, the interpreter tries to parse the if statement and gets confused.

提交回复
热议问题