title: Scripting automated postgres setup
body: <p>I'm scripting a system setup and already have postgres installed.  Here is a test script (run as root) to try and report the working directory in postgres.  Calling <code>pwd</code> as postgres gives <code>/var/lib/postgresql</code>.  But the test..</p>
  
  <pre><code>#!/bin/bash
  su - postgres
  pwd &gt; /home/me/postgres_report
  exit
  </code></pre>
  
  <p>.. fails (obviously) and reports the original working directory.  And afterwards the bash shell is stuck in postgres, suggesting the commands are not being called in right order.  I understand the bash environmental issues here.  I don't have a clue how to do what I need to do, which is automate a postgres process that I can easily do interactively (i.e. step into postgres, execute a command, and exit).  Any pointers?</p>