title: Why string with question mark (?) is not printed in the for batch statement
body: <p>Why the string with question mark is not printed (from command prompt)?</p>
  
  <p>A code example:
  <code>FOR %A IN (--eval string?) DO ECHO %A</code></p>
  
  <p>The code will print only <code>--eval</code> but ignores <code>string?</code></p>
  
  <p>Is there a workaround to get it printed?</p>
  
  <p>I have tried to:</p>
  
  <ul>
  <li>enclose it in double quotes <code>"string?"</code></li>
  <li>tried to escape it <code>"string^?"</code> or <code>"string^^^?"</code> like with bang <code>!</code></li>
  <li>tried to double the <code>??</code> </li>
  <li>tried combination of these</li>
  </ul>
  
  <p>Nothing seems to work.  This seems to be a bug.</p>
  
  <p><strong>Edit</strong> base on the answer and question at comment.</p>
  
  <ul>
  <li><p><em>What do I expect?</em>
  I would expect having both options --eval string? printed.</p></li>
  <li><p><em>What I'm trying to achieve?</em>
  I tried to give a simplification of my final goal.</p></li>
  </ul>
  
  <p>In the end, I wish to have both strings in the <code>!temp_string!</code> variable (in the below <code>test.bat</code> example).</p>
  
  <p>An example based on the real code:</p>
  
  <p><code>test.bat</code> example:</p>
  
  <pre><code>@ECHO OFF
  SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
  
  ECHO "First argument outside FOR statement: %~1"
  ECHO "Second argument outside FOR statement: %~2"
  
  FOR %%A IN (%*) DO (
      ECHO "First inside FOR argument: %~1"
      ECHO "Second inside FOR  argument: %~2"
  
      SET "temp_string=%%~A"
      ECHO !temp_string!
  )
  </code></pre>
  
  <p>If you execute the text.bat without the <code>?</code> in question like:</p>
  
  <p><code>test.bat --eval --test</code>  it will correctly show the both strings.</p>
  
  <p>The result:</p>
  
  <pre><code>"First argument outside FOR statement: --eval"
  "Second argument outside FOR statement: --test"
  "First inside FOR argument: --eval"
  "Second inside FOR  argument: --test"
  --eval
  "First inside FOR argument: --eval"
  "Second inside FOR  argument: --test"
  --test
  </code></pre>
  
  <p>However, if you run it with the same parameter, but containing <code>?</code> </p>
  
  <p><code>test.bat --eval --test?</code>  </p>
  
  <p>The result is incorrect:</p>
  
  <pre><code>"First argument outside FOR statement: --eval"
  "Second argument outside FOR statement: --test?"
  "First inside FOR argument: --eval"
  "Second inside FOR  argument: --test?"
  --eval
  </code></pre>
  
  <p>If you wish to see the real code, which is here simplified, you can find it <a href="https://bitbucket.org/-tukanos-/stx_launcher/src/54076b1c6f1459fd88772e1413e86f8d656705fe/smalltalk.bat?at=default&amp;fileviewer=file-view-default#smalltalk.bat-783" rel="nofollow noreferrer">here</a> around line 783.</p>
  
  <p><strong>Second edit</strong></p>
  
  <p>I'm now trying to get the value of the <code>%%A</code> from the proposed solution by @dbenham.</p>
  
  <p>The <code>%test%</code> variable is still empty in both cases:</p>
  
  <pre><code>@echo off
  
  setlocal disableDelayedExpansion
  
  set "string=--eval string? ;hello &lt;&amp;|&gt;! "^&lt;^&amp;^|^&gt;!""
  set string
  echo(
  
  setlocal enableDelayedExpansion
  for %%n in (^"^
  %= This results in a quoted newline character =%
  ^") do for /f delims^=^ eol^= %%A in ("!string: =%%~n!") do (
      if "!!" equ "" endlocal set "test=%%~A"
      echo "A value:" %%A
      echo "Test value:" %test%
  )
  
  echo %test%
  </code></pre>
  
  <p>The output:</p>
  
  <pre><code>string=--eval string? ;hello &lt;&amp;|&gt;! "&lt;&amp;|&gt;!"
  
  "A value:" --eval
  "Test value:"
  "A value:" string?
  "Test value:"
  "A value:" ;hello
  "Test value:"
  "A value:" &lt;&amp;|&gt;!
  "Test value:"
  "A value:" "&lt;&amp;|&gt;!"
  "Test value:"
  ECHO is off.
  </code></pre>
  
  <p><strong>Third and Forth Edit</strong> - The answer.</p>
  
  <p>Based the dbenham &amp;&amp; Stephan I'm posting working code with which I'm satisfied.
  Note: The dbenham's nasty <code>"^&lt;^&amp;^|^&gt;!"</code> are not working here, but I decided I don't needed it.</p>
  
  <pre><code>@echo off
  REM works for all!!! --&gt; *.bat -string? :hello "&lt;&amp;|&gt;!"
  
  setlocal disableDelayedExpansion
  
  :process_arguments
  :: Process all arguments in the order received
  if defined %1 (
      ECHO %1
      SET "string=%string% %~1"
      shift
      goto:process_arguments
  )
  
  echo(
  
  setlocal enableDelayedExpansion
  for %%n in (^"^
  %= This results in a quoted newline character =%
  ^") do for /f "eol= delims=" %%A in ("!string: =%%~n!") do (
      if "!!" equ "" endlocal 
      set "test=%%~A"
      echo "In for loop - a value: %%A"
      CALL :testing_value "%%A"
  )
  :: END
  goto :eof
  
  :: echo "Outside test:" %test%
  setlocal disableDelayedExpansion
  
  :testing_value
    set "test=%~1"
    set test
    echo "Calling Subroutine: %test%"
    echo:
  </code></pre>
  
  <p>Thank you your guidance! </p>