title: Parsing a comma separated file in a bash script with a while loop
body: <p>I'm trying to parse a comma separated file similar to the following, and extract each field into a variable:</p>
  
  <pre><code>bob,mechanic,single,swimming,/bob/tmp,batman,
  joe,architect,married,tennis,/joe/tmp,superman,34
  </code></pre>
  
  <p>With this script:</p>
  
  <pre><code>#!/bin/bash
  
  #|| [[ -n "$input" ]]
  
  while IFS=, read -r a b c d e f g; do
      echo "$a"
  
  done &lt; "commafile.txt"
  </code></pre>
  
  <p>But when I run the script (called parsecommas) with ./parsecommas from the command line, the script terminates immediately without any output.</p>
  
  <p>What am I doing wrong? I'm running OSX Yosemite and am using xcode to edit the script, then terminal to run it. I've checked for faulty invisibles, but have found none. commafile.txt is in the same directory as the bash script parsecommas.</p>
  
  <p>EDIT: After running a c++ program and only being able to read the last line of a file, I've realized that this problem may not be with my code but the method which I've used to create text files. I used</p>
  
  <pre><code>touch commafile.txt
  </code></pre>
  
  <p>to create my file, and I was only able to read the last line of the file when using getline(file, line) in a c++ program. Has anyone else run into this problem before? What could be wrong with my Mac/Text Editor?</p>
  
  <pre><code>cat commafile.txt
  </code></pre>
  
  <p>Only prints the last line in the file, while when I open the file in either XCode or TextEditor all of the lines are displayed. I copy-pasted the contents of a word doc in a box shaped field to commafile.txt.</p>