title: Bash: Read args from stdin into array
body: <h1>Problem Description</h1>
  
  <p>Given a plaintext file <code>args.in</code> containing one line of command line arguments, read them into an array.</p>
  
  <h1>Problem Formulation</h1>
  
  <p>We have 4 files:</p>
  
  <hr>
  
  <p><em>args.in</em>:</p>
  
  <pre><code>"ab" c
  </code></pre>
  
  <hr>
  
  <p><em>refimpl.sh</em>:</p>
  
  <pre><code>read -r line
  bash -c "bash showargs.sh $line"
  </code></pre>
  
  <hr>
  
  <p><em>arrayimpl.sh</em>:</p>
  
  <pre><code>arr=()
  
  # BEGIN-------------------------
  # Input comes from stdin.
  # You need to set arr here.
  # END---------------------------
  
  echo "${#arr[@]}"
  for i in "${arr[@]}"; do
      echo "$i"
  done
  </code></pre>
  
  <hr>
  
  <p><em>showargs.sh</em>:</p>
  
  <pre><code>echo "$#"
  for i in "$@"; do
      echo "$i"
  done
  </code></pre>
  
  <hr>
  
  <p>Put them into the same folder. We want you to implement <code>arrayimpl.sh</code> so that</p>
  
  <pre><code>bash refimpl.sh &lt; args.in
  </code></pre>
  
  <p>and</p>
  
  <pre><code>bash arrayimpl.sh &lt; args.in
  </code></pre>
  
  <p>give the same output.</p>
  
  <p>Your solution should only contain a single file <code>arrayimpl.sh</code>.</p>
  
  <h1>Output Example</h1>
  
  <pre><code>2
  ab
  c
  </code></pre>
  
  <hr>
  
  <p>This problem is a better formulation of <a href="https://stackoverflow.com/questions/41316347/bash-split-quoted-string-into-array">this</a> but not a dup of <a href="https://stackoverflow.com/questions/26067249/bash-reading-quoted-escaped-arguments-correctly-from-a-string">this</a>. Some solutions work there but not here. For example, when we have the following input:</p>
  
  <p><code>args.in</code>:</p>
  
  <pre><code>"a\"b" c
  </code></pre>
  
  <p>There is no known solution yet.</p>