Note that there are some explanatory texts on larger screens.

plurals
  1. POHow does the Windows Command Interpreter (CMD.EXE) parse scripts?
    text
    copied!<p>I ran into <a href="http://www.ss64.com" rel="noreferrer">ss64.com</a> which provides good help regarding how to write batch scripts that the Windows Command Interpreter will run.</p> <p>However, I have been unable to find a good explanation of the <strong>grammar</strong> of batch scripts, how things expand or do not expand, and how to escape things.</p> <p>Here are sample questions that I have not been able to solve:</p> <ul> <li>How is the quote system managed? I made a <a href="http://tinyperl.sourceforge.net/" rel="noreferrer">TinyPerl</a> script<br> ( <code>foreach $i (@ARGV) { print '*' . $i ; }</code> ), compiled it and called it this way : <ul> <li><code>my_script.exe "a ""b"" c"</code> → output is <code>*a "b*c</code></li> <li><code>my_script.exe """a b c"""</code> → output it <code>*"a*b*c"</code></li> </ul></li> <li>How does the internal <code>echo</code> command work? What is expanded inside that command?</li> <li>Why do I have to use <code>for [...] %%I</code> in file scripts, but <code>for [...] %I</code> in interactive sessions?</li> <li>What are the escape characters, and in what context? How to escape a percent sign? For example, how can I echo <code>%PROCESSOR_ARCHITECTURE%</code> literally? I found that <code>echo.exe %""PROCESSOR_ARCHITECTURE%</code> works, is there a better solution?</li> <li>How do pairs of <code>%</code> match? Example: <ul> <li><code>set b=a</code> , <code>echo %a %b% c%</code> → <code>%a a c%</code></li> <li><code>set a =b</code>, <code>echo %a %b% c%</code> → <code>bb c%</code></li> </ul></li> <li>How do I ensure a variable passes to a command as a single argument if ever this variable contains double quotes?</li> <li>How are variables stored when using the <code>set</code> command? For example, if I do <code>set a=a" b</code> and then <code>echo.%a%</code> I obtain <code>a" b</code>. If I however use <code>echo.exe</code> from the UnxUtils, I get <code>a b</code>. How comes <code>%a%</code> expands in a different way?</li> </ul> <p>Thank you for your lights.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload