I'm trying to create a postgres role and password from bash. However, it seems I'm struggling with the escaping of quotes.
Running:
$ sudo su - postgres -c '''psql -c "CREATE USER testuser WITH PASSWORD 'somepass';" '''
Produces:
ERROR: syntax error at or near "somepass"
LINE 1: CREATE USER testuser WITH PASSWORD somepass;
Other unsuccessful variations I've tried;
sudo su - postgres -c """psql -c "CREATE USER testuser WITH PASSWORD 'somepass';" """
sudo su - postgres -c $''' psql -c "CREATE USER testuser WITH PASSWORD \'pass\';" '''
How can I deal with the nested quotes, and get postgres to create the role from cli?