title: reading errors returned from psql in a bash script
body: <p>I need to check for errors when running psql from a bash script.  Here's an example of how we're running things in the script:</p>
  
  <pre><code>return_value=$(psql \
  -X \
   $POSTGRES_CONNECTION_STRING \
  -f ./build_table.sql \
  -w \
  -b \
  -A \
  -q \
  -t \
  )
  
  psql_exit_status=$?
  </code></pre>
  
  <p>The above statement works fine <em>unless</em> there's an error in the sql script, in which case I get some error output on the console but <code>return_value</code> is set to zero, as is <code>psql_exit_status</code>.  </p>
  
  <p>The <code>build_table</code> sql script creates a table and imports data from a csv file-- if there are errors in the csv file, or if, say, I intentionally misspell  <code>create tableeeee</code> in the sql script I see psql errors on the screen but no error info is returned as best I can tell.</p>
  
  <p>I've tried using the <code>-o</code> flag in psql to output to a file.  Nothing shows, it's a blank file.  I've also tried adding a <code>2&gt;&amp;1</code> bit after the psql statement to see if I could get some error info that way, but nothing doing.  </p>
  
  <p>What I need is some way to tell that the sql script has exited abnormally and/or crashed, without having to look at the output on the screen.  Is that possible with the way I'm executing psql?  Possible something's up with one of my psql flags?</p>