Page 1 of 1

FOR /F with usebackq usage

Posted: 16 Jul 2021 02:24
by findstr
Hello!

Code: Select all

for /f "tokens=*" %%a in ('dir /b') do @echo %%a

Code: Select all

for /f "usebackq tokens=*" %%a in (`dir /b`) do @echo %%a
If I understand correctly, these 2 code samples output the exact same result.

I've been examining different scripts and found that almost always usebackq is used with operations where for /f is working with the output of a command. Are there some disadvantages related to the usage of single quotes, or some subtle side effects?
Thanks!

Re: FOR /F with usebackq usage

Posted: 16 Jul 2021 03:23
by aGerman
The only relevant use case for USEBACKQ that I'm aware of is if you have to process the content of files. File names with spaces and special characters have to be surrounded with double quotes. (And it's best practice anyway to quote them.)

Steffen