Understanding usebackq

Posted on 2005-05-15
Last Modified: 2008-02-01
I need some help in understanding this command:

FOR /F "usebackq delims==" %i IN (`set`) DO @echo %i

I am particularly confused about the 'usebackq' and what it really does. I am also wondering what ('set') means and what can I replace this with.

I would be appreciative of some examples on the usage of the above and an explanation on its usage.

Thank You.
Question by:ben1211
    LVL 95

    Expert Comment

    by:Lee W, MVP
    Examples of usage can be found by typing:

    FOR /?


    SET /?

    Before I explain further, can you clarify what context you are asking in?  Basically, why do you want to know/what is the script used for?  (Just want to make sure I'm not answering a home work question).
    LVL 4

    Expert Comment


    As leew suggested, you can get much more info by typing /? after the command.
    Following is more specific answer to your question:

    SET is a command to display/set/remove environment variables. Those variables are mostly used in batch files (but there are some more cases where you can use them).
    For example, if you type
    SET NAME=ben1211
    and then you type
    you will see the contents of the variable NAME. You can create a batch file that creates a variable, put data in it according to some actions, and use the data later. Actually, the sky is the limit.

    If you type SET with no arguments, you will see all the variables and their values.

    FOR is used to run a specified command for each file in a set of files, or for each line in a set of lines.

    The command you posted shosws only variable names, without the values.

    Normally, the FOR command should receive parameters inside a signle-quote(') or double-quote (")
    Sometimes, you need to pass a string or command that already has signle or double quote in it.
    So, you use the 'usebackq' which means that you pass a string or command inside a backquote.
    In your case, your command:
    FOR /F "usebackq delims==" %i IN (`set`) DO @echo %i
    could be repalced with this (removed the usebackq, and put the 'set' inside single-quote and not backquote):
    FOR /F "delims==" %i IN ('set') DO @echo %i

    Some batch tutorials and examples:

    For a complete list of commands to use in batch files:

    Good luck,
    LVL 4

    Expert Comment

    Another nice explenation about the FOR command:

    LVL 4

    Accepted Solution

    Hi ben1211

    To answer your question simply:

    SET is the command used to display the system and user environment variables, like PATH and USERNAME.

    If you provide SET with arguments it will set or unset variables.

    The usebackq argument in the FOR command is used in situations where you want FOR to parse strings that contain one or more double quotes. One example would be parsing a CSV formatted string, particularly of the Microsoft variety, which uses double quotes around each field to allow for embedded commas:
    These would not work:
    for /f "tokens=1-3" %a in ("field1","field2","field3") do echo %a %b %c
    for /f "tokens=1-3" %a in (""field1","field2","field3"") do echo %a %b %c
    for /f "tokens=1-3" %a in (`"field1","field2","field3"`) do echo %a %b %c
    for /f "tokens=1-3" %a in ('"field1","field2","field3"') do echo %a %b %c

    This would work:
    for /f "usebackq tokens=1-3" %a in ('"field1","field2","field3"') do echo %a %b %c

    Hope that helps

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Many people tend to confuse the function of a virus with the one of adware, this misunderstanding of the basic of what each software is and how it operates causes users and organizations to take the wrong security measures that would protect them ag…
    Windows 10 is here and for most admins this means frustration and challenges getting that first working Windows 10 image. As in my previous sysprep articles, I've put together a simple help guide to get you through this process. The aim is to achiev…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now