#!/bin/bash SUDOER_PSW= function restofscript(){ pw_productiondatabase= pw_developmentdatabase= servicename= service_dev="${servicename}_dev" sudo -u postgres psql -c "create database $servicename;" sudo -u postgres psql -c "create user $servicename with encrypted password '$pw_productiondatabase';" sudo -u postgres psql -c "grant all privileges on database $servicename to $servicename;" } echo "${SUDOER_PSW}" | sudo -S bash -c "$(declare -f restofscript); restofscript" exit