Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • So quotes "" and [] can be used interchangeably for the purposes of empty varaibles? There's no difference? I thought maybe there is some advantage of using [] compared to ""
    – Jim
    Commented May 8, 2014 at 21:48
  • 8
    @Jim - There is no advantage to using [%var%]==[value]. It would work just as well as ]%var%[==]value[ or XXX%var%==XXXvalue. There is an advantage to using "%var%"=="value" because it will not fail if var contains an unquoted poison character like &.
    – dbenham
    Commented May 9, 2014 at 4:23
  • 1
    @dbenham - however, it will fail if var contains an unquoted poison character like ". Consider SET var="foo bar", which becomes if ""foo bar""==""; which will likely award you a bar""=="" was unexpected at this time.... Commented Aug 24, 2017 at 18:42
  • 1
    @jimbobmcgee - Yes, that is why I always try to keep quotes out of my variable values. If I really want robust code that can handle any content, then I use delayed expansion.
    – dbenham
    Commented Aug 24, 2017 at 19:17