title: using `%*` after `shift`
body: <p>I understand that in a Windows batch file, <code>%*</code> expands to all the command-line arguments, and that <code>shift</code> shifts the numbered command-line arguments <code>%1</code>, <code>%2</code>, etc. but that it does <em>not</em> change the content of <code>%*</code>.</p>
  
  <p>What do I do if I want a version of <code>%*</code> that <em>does</em> reflect the effect of <code>shift</code>?   I understand I could just say <code>%1 %2 %3 %4 %5 %6 %7 %8 %9</code> after shifting but it seems stupid and potentially dangerous that that limits me to a fixed number of arguments.</p>
  
  <p>Although this is not a python-specific question, it may help to understand that the reason I want this behaviour is that I've had to write a batch file  <code>SelectPython.bat</code> that pre-configures certain environment variables, in order to navigate the babel of different Python distros I have (you have to set <code>%PYTHONHOME%</code>, <code>%PYTHONPATH%</code> and <code>%PATH%</code> in certain ways before you can call the Python binary and have confidence that you'll get the right distro).   My current script works fine for setting these variables, but I would like to be able to call it <em>and</em> Python in one line - e.g.:</p>
  
  <pre><code>SelectPython C:\Python35  pythonw.exe myscript.py arg1 arg2 arg3 ...
  </code></pre>
  
  <p>Ideally I want my batch file to use <code>shift</code> to "eat" the first argument, process it accordingly and set up the environment, and then just automatically chain-execute the string formed by rest of the arguments.  The principle is analogous to the way <code>env</code> wraps commands in posix systems:</p>
  
  <pre><code>env FOO=1 echo $FOO     # wrap the `echo` command to be executed in the context of specified environment settings
  </code></pre>
  
  <p>So far I have this - the last line is where the problem is:</p>
  
  <pre><code>@echo off
  set "LOC=%CD%
  if not "%~1" == "" set "LOC=%~1
  if exist "%LOC%\python.exe" goto :Success
  
  echo "python.exe not found in %LOC%"
  goto :eof
  
  :Success
  :: Canonicalize the resulting path:
  pushd %LOC%
  set "LOC=%CD%
  popd
  
  :: Let Python know where its own files are:
  set "PYTHONHOME=%LOC%
  set "PYTHONPATH=%LOC%;%LOC%\Lib\site-packages
  
  :: Put Python's location at the beginning of the system path if it's not there already:
  echo "%PATH%" | findstr /i /b /c:"%PYTHONHOME%" &gt; nul || set "PATH=%PYTHONHOME%;%PYTHONHOME%\Scripts;%PATH%
  
  :: Now execute the rest:
  shift
  if "%~1" == "" goto :eof
  %1 %2 %3 %4 %5 %6 %7 %8 %9
  :: This is unsatsifactory - what if there are more than 9 arguments?
  </code></pre>
  
  <p><strong>UPDATE:</strong>  Thanks to <a href="https://stackoverflow.com/users/2152082/stephan">Stephan</a> my working solution now has the following altered end-section:  </p>
  
  <pre><code>:: Now execute the rest of the arguments, if any:
  shift
  if @%1 == @ goto :eof
  set command=
  :BuildCommand
  if @%1 == @ goto :CommandFinished
  set "command=%command% %1"
  shift
  goto :BuildCommand
  :CommandFinished
  %command%
  </code></pre>