Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As others have already said, parameters passed through the command line can be accessed in batch files with the notation <code>%1</code> to <code>%9</code>. There are also two other tokens that you can use:</p> <ul> <li><code>%0</code> is <strong>the executable (batch file) name as specified in the command line</strong>.</li> <li><code>%*</code> is <strong>all parameters specified in the command line</strong> -- this is very useful if you want to forward the parameters to another program.</li> </ul> <p>There are also lots of important techniques to be aware of in addition to simply how to access the parameters.</p> <h3>Checking if a parameter was passed</h3> <p>This is done with constructs like <code>IF "%~1"==""</code>, which is true if and only if no arguments were passed at all. Note the tilde character which causes any surrounding quotes to be removed from the value of <code>%1</code>; without a tilde you will get unexpected results if that value includes double quotes, including the possibility of syntax errors.</p> <h3>Handling more than 9 arguments (or just making life easier)</h3> <p>If you need to access more than 9 arguments you have to use the command <code>SHIFT</code>. This command shifts the values of all arguments one place, so that <code>%0</code> takes the value of <code>%1</code>, <code>%1</code> takes the value of <code>%2</code>, etc. <code>%9</code> takes the value of the tenth argument (if one is present), which was not available through any variable before calling <code>SHIFT</code> (enter command <code>SHIFT /?</code> for more options).</p> <p><code>SHIFT</code> is also useful when you want to easily process parameters without requiring that they are presented in a specific order. For example, a script may recognize the flags <code>-a</code> and <code>-b</code> in any order. A good way to parse the command line in such cases is</p> <pre><code>:parse IF "%~1"=="" GOTO endparse IF "%~1"=="-a" REM do something IF "%~1"=="-b" REM do something else SHIFT GOTO parse :endparse REM ready for action! </code></pre> <p>This scheme allows you to parse pretty complex command lines without going insane.</p> <h3>Substitution of batch parameters</h3> <p>For parameters that represent file names the shell provides lots of functionality related to working with files that is not accessible in any other way. This functionality is accessed with constructs that begin with <code>%~</code>.</p> <p>For example, to get the size of the file passed in as an argument use</p> <pre><code>ECHO %~z1 </code></pre> <p>To get the path of the directory where the batch file was launched from (very useful!) you can use</p> <pre><code>ECHO %~dp0 </code></pre> <p>You can view the full range of these capabilities by typing <code>CALL /?</code> in the command prompt.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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