如何将'c'添加到从 bash 脚本执行的 psql 命令中?



要设置我的项目,我必须执行相当多的命令,我正在尝试编写脚本。其中一些在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...
^

我如何从我的脚本正确执行这些命令?

你试过了吗?

psql -U postgres -h localhost -p 5433 << 'EOF'
create database test_database
c test_database
i integration-test/src/test/resources/init.sql
EOF

最新更新