Link to home
Start Free TrialLog in
Avatar of ben1211
ben1211Flag for Malaysia

asked on

Understanding usebackq

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.
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Examples of usage can be found by typing:

FOR /?

and

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).
Avatar of ben-gur
ben-gur

Hello,

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
ECHO %NAME%
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:
http://www.computerhope.com/batch.htm#03

For a complete list of commands to use in batch files:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx

Good luck,
Adam.
ASKER CERTIFIED SOLUTION
Avatar of LittleRed1
LittleRed1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial