In essence, the question is how to execute: CREATE DATABASE test_db; from bash without connecting to psql console

  • Well, it’s not connecting at all, it’s just that commands can be sent not from the console, but to the standard input: echo "create database ..." | psql ... echo "create database ..." | psql ... - Mike

1 answer 1

Hold, the PGPASSWORD variable is needed in case you have password access

 #!/bin/bash export PGPASSWORD="passs" test=$(psql -h localhost -t -U username -c "CREATE DATABSE test.db") echo $test