0

I'm trying to use the following in a shell (/bin/sh) script but I keep getting errors:

su postgres -c "/usr/bin/psql -c \'CREATE ROLE user WITH SUPERUSER LOGIN PASSWORD \'$password;"

It seems that something with the quoting is wrong, but I can't find what is it. I should pass the variable $password and the command as postgres user. Can someone help me?

Thanks in advance

1 Answer 1

1

Your quotes are not even matched. You can escape double quotes within double quotes, and there is no need to escape single quotes.

su postgres -c "/usr/bin/psql -c \"CREATE ROLE username WITH SUPERUSER LOGIN PASSWORD '$password';\""

Note that user is not a valid name in SQL.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.