I'm trying to create a psql database using a shell script, I do not want to add the script executor to sudoer file.
We can run below command if I give the user sudo permissions, I want to do it without any extra permissions to normal user.
sudo -u username createdb $dbname read -e dbname psql -U secureall -c 'create database $dbname;'
I was able to read the dbname, but the command doesn't take any variables.
[[email protected] ~]$ psql -U username -c 'create database $dbname;' ERROR: syntax error at or near "$" LINE 1: create database $dbname;
How do I use variables in db command set or is there a workaround?