C:\_G\WWW\~ELISANET\INFO\tscmd176.html
<http://www.elisanet.fi/tsalmi/info/tscmd176.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Tue 11-Dec-2018 17:23:12

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



176} How to get the rest of the command line parameters?

The solution already is embedded in some other problem solutions in this FAQ collection. However, it is given here as a separate item to focus on the current question only. You may also wish to see e.g. item #40.

  @echo off & setlocal enableextensions
  for /f "tokens=1*" %%a in ('echo.%*') do set rest_=%%b
  echo rest_=%rest_%
  endlocal & goto :EOF

The output could be e.g.
  C:\_M>C:\_D\TEST\CMDFAQ.CMD 1 2 "3 & 3.5" 4
  rest_=2 "3 & 3.5" 4
or
  C:\_M>C:\_D\TEST\CMDFAQ.CMD 1
  rest_=
The echo. prevents confusion in the latter output example.

As an aside note in the demonstration below how a shift command has no effect on the %* modifier that represents all the arguments passed to the script.
  @echo off & setlocal enableextensions
  shift
  rem This is not affected
  for /f "tokens=1*" %%a in ('echo.%*') do set rest_=%%b
  echo rest_=%rest_%
  rem This is affected
  echo %%~2="%~2"
  endlocal & goto :EOF

The output could be e.g.
  C:\_M>C:\_D\TEST\CMDFAQ.CMD 1 2 "3 & 3.5" 4
  rest_=2 "3 & 3.5" 4
  %~2="3 & 3.5"

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd176.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd176
http://www.elisanet.fi/tsalmi/info/tscmd176.html
file:///c:/_g/www/~elisanet/info/tscmd176.html