title: bash script to update postgres database
body: <p>I have some html data stored in text files right now. I recently decided to store the HTML data in the pgsql database instead of flat files. Right now, the 'entries' table contains a 'path' column that points to the file. I have added a 'content' column that should now store the data in the file pointed to by 'path'. Once that is complete, the 'path' column will be deleted. The problem that I am having is that the files contain apostrophes that throw my script out of whack. What can I do to correct this issue??</p>
  
  <p>Here is the script</p>
  
  <pre><code>#!/bin/sh
  dbname="myDB"
  username="username"
  fileroot="/path/to/the/files/*"
  
  for f in $fileroot
  do
  psql $dbname $username -c "
    UPDATE entries
    SET content='`cat $f`'
    WHERE id=SELECT id FROM entries WHERE path LIKE '*`$f`';"
  done
  </code></pre>
  
  <p>Note: The logic in the <code>id=SELECT...FROM...WHERE path LIKE ""</code> is not the issue. I have tested this with sample filenames in the pgsql environment.</p>
  
  <p>The problem is that when I <code>cat $f</code>, any apostrophe in <strong>Edit: the contents of</strong> $f closes the SQL string, and I get a syntax error.</p>