db1="community-service-data"
db2="ecomm-data-test"
drop_db="DROP DATABASE ${db1}"
sudo -u postgres -S /bin/bash -c "psql -U postgres -d postgres -c \"${drop_db}\""
drop_db="DROP DATABASE \"ecomm-data-test\";"
sudo -u postgres -S /bin/bash -c "psql -U postgres -d postgres -c \"${drop_db}\""
error
ERROR: syntax error at or near "-"
LINE 1: DROP DATABASE community-service-data
^
I have db names with hyphen in them. I am dropping these databases from a bash script. It keeps complaining about the '-' in the variable. I tried quoting but it doesn't work.
I even tried drop_db="DROP DATABASE \"${db1}\"" If I do in quotes in the psql command line directly then it works.
how can I do it correctly.
Thanks
update:
drop_db=(DROP DATABASE "${db1}")
error:
ERROR: syntax error at end of input
LINE 1: DROP
^
`my_table`?drop_db=(DROP DATABASE "${db1}")and thensudo -u postgres -S /bin/bash -c "psql -U postgres -d postgres -c '${drop_db[@]}'", does that work?bashto callpsqlinstead of callingpsqldirectly? Feels like some quoting is likely being eaten up in this layering.