Brackets can be useful to make complex commands more readable and/or to span commands across several lines.
(command) ( command ) e.g. IF EXIST C:\pagefile.sys ( ECHO pagefile found on C: drive)
The use of brackets is only required if the command is run over several lines
IF EXIST filename (
) ELSE (
echo The file was not found.
The IF statement does not use any great intelligence when evaluating Brackets, so for example the command below will fail:
IF EXIST MyFile.txt (ECHO Some(more)Potatoes)
This version will work:
IF EXIST MyFile.txt (ECHO Some[more]Potatoes)
It is worth noting that although brackets are legal in NTFS pathnames, such brackets will be misinterpreted by the command processor.
Testing Numeric values
Do not use brackets or quotes if you are comparing numeric values with an
IF (2) GEQ (15) echo "bigger"
IF "2" GEQ "15" echo "bigger"
Will perform a character comparison and will echo "bigger"
however the command
IF 2 GEQ 15 echo "bigger"
Will perform a numeric comparison and works as expected.
This is opposite to the SET /a command where quotes are required.
|file: /Techref/os/win/winnt/brackets.htm, 1KB, , updated: 2007/8/16 14:08, local time: 2023/6/7 08:17,
|©2023 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.sxlist.com/techref/os/win/winnt/brackets.htm"> Using brackets to group expressions</A>
|Did you find what you needed?|
Welcome to sxlist.com!
& kind contributors
just like you!
Please don't rip/copy
Copies of the site on CD
are available at minimal cost.
Welcome to www.sxlist.com!