title: How can I Enter into postgres bash command line and exit using shell script?
body: <p>I'm beginner in writing script in linux. Can anyone please help!</p>
  
  <p>From terminal I enter into postgres bash command line by typing:</p>
  
  <p>[root@localhost Desktop]# su - postgres</p>
  
  <p>-bash-3.2$</p>
  
  <p>then I can create user,db from there and I can exit by typing "exit" command.</p>
  
  <p>How can I do this by script? I've written a scrip but that does enter into bash but doesn't run the commands. I want to enter into bash, create a user &amp; db then exit. My scripts concept is given below: </p>
  
  <pre><code>#!/bin/bash
  createuser -P -s -e asterisk
  createdb --owner=asterisk asterisk2
  </code></pre>