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: syntax error at or near "-"
LINE 1: DROP DATABASE community-service-data
^
我的数据库名称中有连字符。我正在从 bash 脚本中删除这些数据库。它一直抱怨变量中的“-”。我试过引用,但没有用。我甚至试过drop_db="DROP DATABASE \"${db1}\""
如果我直接在 psql 命令行中用引号引起来,它就会起作用。
我怎样才能正确地做到这一点。
谢谢
更新:
drop_db=(DROP DATABASE "${db1}")
错误:
ERROR: syntax error at end of input
LINE 1: DROP
^