Timeline for Square bracket notation around variable in cmd / DOS batch scripts
Current License: CC BY-SA 4.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 6, 2019 at 11:29 | history | edited | Stephan | CC BY-SA 4.0 |
added 10 characters in body
|
Aug 24, 2017 at 19:17 | comment | added | dbenham | @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. | |
Aug 24, 2017 at 18:42 | comment | added | jimbobmcgee |
@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. ...
|
|
May 9, 2014 at 9:04 | vote | accept | Jim | ||
May 9, 2014 at 5:55 | history | edited | Stephan | CC BY-SA 3.0 |
added 153 characters in body
|
May 9, 2014 at 4:23 | comment | added | dbenham |
@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 &.
|
|
May 8, 2014 at 21:48 | comment | added | Jim | 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 "" | |
May 8, 2014 at 21:46 | history | edited | Stephan | CC BY-SA 3.0 |
added 2 characters in body
|
May 8, 2014 at 21:40 | history | answered | Stephan | CC BY-SA 3.0 |