title: How to read in csv file to array in bash script
body: <p>I have written the following code to read in my csv file (which has a fixed number of columns but not a fixed number of rows) into my script as an array. I need it to be a shell script.</p>
  
  <pre><code>usernames   x1    x2   x3  x4
  username1,  5     5    4   2
  username2,  6     3    2   0
  username3,  8     4    9   3
  </code></pre>
  
  <p>My code</p>
  
  <pre><code>#!/bin/bash
  set oldIFS = $IFS
  set IFS=,
  read -a line &lt; something.csv
  </code></pre>
  
  <p>another option I have used is </p>
  
  <pre><code>#!/bin/bash
  while IFS=$'\t' reaad -r -a line
  do 
  echo $line
  done &lt; something.csv
  </code></pre>
  
  <p>for both I tried some test code to see what the size of the array line would be and I seem to be getting a size of 10 with the first one but the array only outputs username. For the second one, I seem to be getting a size of 0 but the array outputs the whole csv.</p>
  
  <p>Help is much appreciated!</p>