title: Unix: appending the values to dynamic array for later use
body: <p>I have input read from a file and each line in the file will be having fields terminated by '|'. I wanted to loop to an array so that I can use in my later code. This what I have arrived so far, but looping thru array does not work.</p>
  
  <pre><code>#!/bin/ksh
  
  TEMP="abc1|abc2|abc3 1;abc4 1"
  rest=$TEMP
  field=()
  
  while [ -n "$rest" ]
  do
          str=${rest%%\|*}
          field+=("$str")
          [ "$rest" = "${rest/\|/}" ] &amp;&amp; rest= || rest=${rest#*\|}
          #print $str
  done
  
  for x in ${field}
  do
          echo $x
  
  done
  </code></pre>
  
  <p>print $str works fine, but when I loop to get the value I don't get the values.
  Any help to resolve this.</p>
  
  <p>Thank you.</p>