如何将 '\c' 添加到从 bash 脚本执行的 psql 命令?
How do I add '\c' to a psql command executed from a bash script?
要设置我的项目,我必须执行很多命令,并且我正在尝试编写脚本。其中一些在 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
要设置我的项目,我必须执行很多命令,并且我正在尝试编写脚本。其中一些在 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