title: Test a return value in bash
body: <p>I am trying to write a bash script that creates and sets up a postgres database if it does not already exist.  Following <a href="https://stackoverflow.com/questions/14549270/check-if-database-exists-in-postgresql-using-shell">this</a>, I've got to this script:</p>
  
  <pre><code>if [ `psql -l | grep mydb | wc -l` -eq 1]
  then
      echo "Database exists"
  else:
      echo "Creating database"
      ...
  fi
  </code></pre>
  
  <p>But it always returns with <code>"Database exists"</code>, regardless of whether the database is there or not.  I've also tried <code>[ "` psql -l | grep mydb | wc`" == "1" ]</code>, but it gives the same result.  What am I doing wrong?</p>
  
  <p><strong>EDIT</strong> The output of <code>psql -l</code> and <code>psql -l | grep mydb</code> are:</p>
  
  <pre><code>$ psql -l
                                         List of databases
      Name    |    Owner     | Encoding |   Collate   |    Ctype    |   Access privileges   
  ------------+--------------+----------+-------------+-------------+-----------------------
   geoserver  | adminhgv7rj4 | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
   postgres   | postgres     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
   project_db | gis_group    | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
   template0  | postgres     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
              |              |          |             |             | postgres=CTc/postgres
   template1  | postgres     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
              |              |          |             |             | postgres=CTc/postgres
  (6 rows)
  $ psql -l | grep mydb
  $
  </code></pre>