title: Split comma separated and quoted string into an array in Bash
body: <p>I need to split a comma separated, but quoted list of strings into an indexed bash array in a script.</p>
  <p>I know there are a lot of posts on the web in general and also on SO that show how to create an indexed array from a given line / string, but I could not find any example that does the array elements the way I need.  I apologise, if I have missed any obvious examples from SO itself.</p>
  <p>I am reading a file that I receive from someone, and cannot change it.</p>
  <p>The file is formatted like this</p>
  <pre><code>&quot;Grant ACL&quot;,&quot;grantacls.sh&quot;
  &quot;Revoke ACL&quot;,&quot;revokeacls.sh&quot;
  &quot;Get ACls for Topic&quot;,&quot;topicacls.sh&quot;
  &quot;Get Topics for User with ACLs&quot;,&quot;useracls.sh&quot;
  </code></pre>
  <p>I need to create an array for each line above where the separator is comma - and each of the quoted string will be an array element.  I have tried various options.  The latest attempt was using a construct like this - copied from some example on the web</p>
  <pre><code>  parseScriptMapLine=${scriptName[$IN_OPTION]}
    mapfile -td ',' script1 &lt; &lt;(echo -n &quot;${parseScriptMapLine//, /,}&quot;)
    declare -p script1
    echo &quot;script1 $script1&quot;
  </code></pre>
  <p>where script name is an associative array created from the original file, whose format is with 1, 2, etc. as the key and the other part after '=' sign as value.</p>
  <p>The above snippet prints
  <code>script1 </code></p>
  <p>And the value part I need to split into an indexed array, so that I can pass the second element as a parameter.  When creating indexed array from the value string, if I have to lose the quotes, that is fine or if it creates the elements with the quotes, that is fine too.</p>
  <pre><code>1=&quot;Grant ACL&quot;,&quot;grantacls.sh&quot;
  2=&quot;Revoke ACL&quot;,&quot;revokeacls.sh&quot;
  3=&quot;Get ACls for Topic&quot;,&quot;topicacls.sh&quot;
  4=&quot;Get Topics for User with ACLs&quot;,&quot;useracls.sh&quot;
  </code></pre>
  <p>I have looked at a lot of examples, but haven't been able to get this particular requirement working.</p>
  <p>Thank you</p>