title: How to pass the file name dynamically to awk when awk is used in command substitution to build the shell array?
body: <p>Here is the script I am using and this is working fine</p>
  
  <pre><code># This is a test file which we are creating and this will be used to create the shell array
  cat &gt; test.txt &lt;&lt;End-of-message
  1A|1B|1C|1D
  2A|2B|2C|2D
  3A|3B|3C|3D
  4A|4B|4C|4D
  End-of-message
  
  set -A col1_arr `awk 'BEGIN { FS = "|" }{print $1}' test.txt`
  
  i=0
  while [ $i -lt ${#col1_arr[@]} ]
  do
      echo "Column 1 is:${col1_arr[$i]}"
      (( i=i+1 ))
  done
  
  rm test.txt # delet the test file
  </code></pre>
  
  <p>I do not want to hard-code test.txt and want to be able to pass it as a variable. Please advise.</p>