【发布时间】:2021-10-03 11:56:06
【问题描述】:
要设置我的项目,我必须执行很多命令,并且我正在尝试编写脚本。其中一些在 psql 中;所以通常我会去
psql -U postgres -h localhost -p 5433
(psql) create database test_database
(psql) \c test_database
(psql) \i integration-test/src/test/resources/init.sql
.init.sql 包含用模拟数据填充数据库的内容。
在我的 bash 脚本中,我尝试将其减少到
psql -U postgres -h localhost -p 5433 -c "create database test_database; \c test_database; \i integration-test/src/test/resources/init.sql"
但是,这让我很兴奋
ERROR: syntax error at or near "\"
LINE 1: create database test_database; \c fcs_analytics; \i integrat...
^
如何从我的脚本中正确执行这些命令?
【问题讨论】: