title: How to alter role from command line in postgresql?
body: <p>I'm trying to build a setup script to automate the development environments creation, but I'm having trouble both trying to pipe or using the -c modifier for psql.</p>
  
  <p>I've tried:</p>
  
  <pre><code>sudo su postgres psql -c "ALTER ROLE postgres WITH password 'pass'"
  </code></pre>
  
  <p>and </p>
  
  <pre><code>sudo su postgres psql -c "ALTER ROLE postgres WITH password 'pass';"
  </code></pre>
  
  <p>Both of which say "ALTER: command not found"</p>
  
  <p>I've also tried pipe, but I'm not able to combine it with su correctly</p>
  
  <p>eg: I tried something like </p>
  
  <pre><code>sudo su postgres echo "ALTER ROLE postgres WITH password 'pass'" | psql 
  </code></pre>
  
  <p>But postgres can't execute "echo"</p>
  
  <p>And:</p>
  
  <pre><code>echo "ALTER ROLE postgres WITH password 'pass'" | sudo su psql
  </code></pre>
  
  <p>Which just doesn't work.</p>
  
  <p>So, my first question is: how can I execute this simple command from a sh file?</p>
  
  <p>And the second one, less related: how can I use different users in the commands chained with pipe? </p>