Skip to content Skip to sidebar Skip to footer

Able To Create Postgres Database In Command Line But Not In Bash Script

I am trying to write a bash script that automates created and filling a database. I found that I can use these commands to create a database in the command line: sudo su postgres p

Solution 1:

after you sudo su you become another user. at this point script will stop executing, until you exit the user, then it will go on executing.

instead if you want to run something as postgres , try smth like this:

sudo su postgres <<EOF
psql -c 'CREATE DATABASE routing;'
EOF
exit

Post a Comment for "Able To Create Postgres Database In Command Line But Not In Bash Script"