title: Batch script pass multiple parameters to call
body: <p>I have written a script that contains a function that should loop through a list and return a value given the index of the item in said list. I have a function called: <code>:find</code> that should take 2 arguments: the list and the item position. I am unsure of how to process the multiple parameters in the function. This script runs fine if I replace <code>%LIST%</code> with <code>%MY_LIST%</code> inside the loop and I remove the <code>%MY_LIST%</code> from the argument list tht is passed to <code>call :find</code>, but I really want to know how to pass multiple arguments. I take it that they are just passed to the function as a whole string...</p>
  
  <pre class="lang-batch prettyprint-override"><code>@echo off
  setlocal enableDelayedExpansion
  cls
  
  :: ----------------------------------------------------------
  :: Variable declarations
  :: ----------------------------------------------------------
  set RETURN=-1
  set MY_LIST=("foo" "bar" "baz")
  set TARGET_INDEX=1
  
  :: ----------------------------------------------------------
  :: Main procedure
  :: ----------------------------------------------------------
  call :log "Finding item %TARGET_INDEX%..."
  call :find %MY_LIST% %TARGET_INDEX%
  call :log "The value is: %RETURN%"
  goto Exit
  
  :: ----------------------------------------------------------
  :: Function declarations
  :: ----------------------------------------------------------
  :find
  call :log "Called `:find` with params: [%*]"
  set /a i=0
  set LIST=%~1 &amp; shift
  
  for %%a in %LIST% do (
      if !i! == %~1 (
          set RETURN=%%a
      )
      set /a i=!i!+1
  )
  goto:EOF
  
  :printDate
  for /f "tokens=2-4 delims=/ " %%a in ('echo %DATE%') do (
    set mydate=%%c/%%a/%%b)
  for /f "tokens=1-3 delims=/:./ " %%a in ('echo %TIME%') do (
    set mytime=%%a:%%b:%%c)
  echo|set /p="[%mydate% %mytime%] "
  goto:EOF
  
  :log
  call :printDate
  echo %~1
  goto:EOF
  
  :: ----------------------------------------------------------
  :: End of script
  :: ----------------------------------------------------------
  
  :Exit
  </code></pre>
  
  <hr>
  
  <p><strong>Update</strong> </p>
  
  <p>My script now works fine; thanks to nephi12. <a href="http://pastebin.com/xGdFWmnM" rel="nofollow">http://pastebin.com/xGdFWmnM</a></p>