FOR /F with usebackq usage

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
findstr
Posts: 17
Joined: 09 Jun 2021 12:36

FOR /F with usebackq usage

#1 Post by findstr » 16 Jul 2021 02:24

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!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: FOR /F with usebackq usage

#2 Post by aGerman » 16 Jul 2021 03:23

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

Post Reply