title: pass string as arguments with spaces to bash function
body: <p>I'm trying to pass a string to a function.  The string contains multiple arguments and some of the arguments may begin with multiple spaces.</p>
  
  <pre><code>#!/bin/bash
  test_function() {
      echo "arg1 is: '$1'"
      echo "arg2 is: '$2'"
      echo "arg3 is: '$3'"
  }
  
  a_string="one two \"  string with spaces in front\""
  result=$(test_function $a_string)
  echo "$result"
  </code></pre>
  
  <p>Here is the output actually produced:</p>
  
  <pre><code>arg1 is: 'one'
  arg2 is: 'two'
  arg3 is: '"'
  </code></pre>
  
  <p>Here is an example of the output I am trying to achieve:</p>
  
  <pre><code>arg1 is: 'one'
  arg2 is: 'two'
  arg3 is: '  string with spaces in front'
  </code></pre>
  
  <p>How can I store arguments containing spaces in a string like this to later be passed to a function?</p>
  
  <p>Although it can be done with an array, I need to first convert the string into the array values.</p>