title: Bash Script exiting without error while using diff
body: <p>I'm fairly new to using bash and was trying to create an autograder script for running some test cases. Currently my bash script seems to be acting strangely; when I have the -e flag set bash will just exit when a diff has a positive size, and when the -e flag is not set the script ignores any differences in the diff files and says that all tests passed.</p>
  
  <p>The script exits immediately after the "write_diff_out=...." command, the next line is not printed. I've only included the diffing portion of the script as everything else runs fine (the files all exist as well).</p>
  
  <pre><code># Validate outputs and print results
  echo "&gt; Comparing current build's final memory output with golden memory output...";
  for file in `ls test_progs`;
  do
      file=$(echo $file | cut -d '.' -f1);
      echo "$file";
      write_diff_out=$(diff ./log/$file.writeback.out ./log/$file.writeback.gold.out &gt; ./diff/$file.writeback.diff);
      echo "Finished write_diff";
      program_diff_out=$(diff -u &lt;(grep -E '@@@' ./log/$file.program.out) &lt;(grep -E '@@@' ./log/$file.program.gold.out) &gt; ./diff/$file.program.diff);
      echo "Finished program diff";
  
      if [ -z "$write_diff_out" ] &amp;&amp; [ -z "$program_diff_out" ]; then
          printf "%20s:\e[0;32mPASSED\e[0m\n" "$file";
      else
          printf "%20s:\e[0;31mFAILED\e[0m\n" "$file";
      fi
  done
  echo "&gt; Done comparing test outputs.";
  </code></pre>
  
  <p>Feel free to suggest a better way of formatting the diff commands as well, I know there are different methods of writing them.</p>