title: Can I run 'su' in the middle of a bash script?
body: <p>Can I change/su user in the middle of a script?</p>
  <pre><code>if [ &quot;$user&quot; == &quot;&quot; ]; then
    echo &quot;Enter the table name&quot;;
    read user
  fi
  
  gunzip *
  chown postgres *
  su postgres 
  dropdb $user
  psql -c &quot;create database $user with encoding 'unicode';&quot; -U dbname template1
  psql -d $user -f *.sql
  </code></pre>