I'm trying to automate the creation of a PostgreSQL user with a bash script.
I'm specifying the initial password as prompted by the "createuser" command, and I'd like to do it in bash, which I think implies a here document.
Yet the prompt answers I've specified don't make it to the "createuser" command! Here is directly entering the script on the command line:
-bash-4.1$ createuser mynewuser -P <<ENDBEFORETHIS > fakepassword > fakepassword > n > n > n > ENDBEFORETHIS Enter password for new role: -bash-4.1$
Why is that?
- How can I get the input to the createuser script?
- is there a more effective way of doing this?
For those just joining us, the "<<" is known as a here-document or a "heredoc", which essentially pipes the next few lines to the command as stdin. It runs until the matching label specified after the "<<".