コマンド自体の変数だけでなく、接続パラメーターとして psql コマンドに bash-variables を挿入しようとしているときに、私は気が狂っています。次の例は正しく機能します。
psql -U postgres -h localhost -p 5432 -c "CREATE DATABASE testdb WITH ENCODING='UTF8' OWNER=postgres TABLESPACE=pg_default TEMPLATE=template_postgis CONNECTION LIMIT=-1;"
今私は、特別な構成ファイルに保持されている変数を介して各パラメーターを交換しようとしています。
動かない例:
dbserver=localhost
dbport=5432
dbowner=postgres
dbname=testdb
dbtemplate=template_postgis
dbtablespace=pg_default
psql -U '$dbowner' -h '$dbserver' -p '$dbport' -c "CREATE DATABASE '$dbname' WITH ENCODING='UTF8' OWNER='§dbowner' TABLESPACE='$dbtablespace' TEMPLATE='$dbtemplate'
CONNECTION LIMIT=-1;"
いくつかの引用符、逆引用符、およびエスケープスラッシュをすでに試しましたが、それでもうまくいきません。前もって感謝します、knutella