title: KSH scripting: how to split on ',' when values have escaped commas?
body: <p>I try to write KSH script for processing a file consisting of name-value pairs, several of them on each line.</p>
  
  <p>Format is:</p>
  
  <pre><code>NAME1 VALUE1,NAME2 VALUE2,NAME3 VALUE3, etc
  </code></pre>
  
  <p>Suppose I write:</p>
  
  <pre><code>read l
  IFS=","
  set -A nvls $l
  echo "$nvls[2]"
  </code></pre>
  
  <p>This will give me second name-value pair, nice and easy. Now, suppose that the task is extended so that values could include commas. They should be escaped, like this:</p>
  
  <pre><code>NAME1 VALUE1,NAME2 VALUE2_1\,VALUE2_2,NAME3 VALUE3, etc
  </code></pre>
  
  <p>Obviously, my code no longer works, since "read" strips all quoting and second element of array will be just "NAME2 VALUE2_1". </p>
  
  <p>I'm stuck with older ksh that does not have "read -A array". I tried various tricks with "read -r" and "eval set -A ....", to no avail. I can't use "read nvl1 nvl2 nvl3" to do unescaping and splitting inside read, since I dont know beforehand how many name-value pairs are in each line.</p>
  
  <p>Does anyone have a useful trick up their sleeve for me?</p>
  
  <p>PS
  I know that I have do this in a nick of time in Perl, Python, even in awk. However, I have to do it in ksh (... or die trying ;)</p>