How to prevent batch echo brackets
Batch file
@C:
@CD \Users
@for /D %%d in ("*") do (
@echo "%%d"
)
Output
C:\Users>()
"Administrator"
...
C:\Users>()
"Public"
Add in the first line @echo off
and remove in the next lines @
@echo off
cd /d C:\Users
for /D %%d in ("*") do (
echo "%%d"
)
@CD /d C:\Users
@for /D %%d in ("*") do @echo "%%d"
Obs.:
CD /D C:\User
/D == goto Drive, so is the same:
C:
CD User
Some further reading:
[√] CD
[√] For Loop
[√] For /F Loop
[√] Echo on | off
I don't see an answer for the specific OP's question: preventing batch echo of brackets when used on the FOR command as in the example. Yes, they can be removed in this case, but assuming one may indeed wish to suppress them from command echo (as was actually asked) since they do serve a useful purpose even for a single command if only for readability...
If command ECHO is OFF (the default), the leading @ (at)sign suppresses echoing the current command. In a FOR loop, everything after "do " ["d"-"o"-space] becomes a new current command for the purposes of iterating the FOR loop, including parenthetical () command blocks. Each (or the only) command in those blocks can be echo-suppressed with a leading @, as in the original example. If every command inside the block is echo-suppressed with a leading @, then the only thing echoed would be the empty set of brackets.
Alternatively, the entire command block can have all the next level commands within echo-suppressed by leading the entire block with @:
@C:
@CD \Users
@for /D %%d in ("*") do @(
echo "%%d"
)
By moving the leading @ outside the command block, the empty set originally echoed is also echo-suppressed.
IF
blocks because they don't use DO
.