linux - 使用 bash 部署 postgresql - 语法错误

标签 linux bash postgresql shell debian

这是我的部署片段:

APP="test"
DBPASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
sudo -u postgres -H createuser --no-createrole --no-superuser --no-createdb $APP_main
sudo -u postgres -H createdb -O $APP_main $APP_main
sudo -u postgres -H psql -c "alter user $APP_main with password '$DBPASS'"

这是我的注销:

/usr/lib/postgresql/9.1/bin/createdb: option requires an argument -- 'O'                              
Try "createdb --help" for more information.                                                           
ERROR:  syntax error at or near "with password"                                                       
LINE 1: alter user  with password 'hCGCly4ZVfu42Dr956ncypuf6mt0lBiY'

谁能解释一下哪里出了问题?我已经指定了 O 参数,它似乎不接受它。

最佳答案

问题出在:

$APP_main

您可能想将 _main 附加到变量 $APP。而是说:

${APP}_main

这将扩展变量 $APP 并将 _main 附加到它。

关于linux - 使用 bash 部署 postgresql - 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22380999/

相关文章:

linux - 我如何在 apache linux 中设置通配符子域?

javascript - 如何让 mocha 递归地在所有子文件夹中执行测试?

postgresql - PostgreSQL 锁定机制中的错误或对该机制的误解

postgresql - postgresql中多列上的多个索引与单个索引

linux - 设置特定模式格式和仅更改数据的最佳方法是什么

java - 在哪里可以找到 JRE 的 native 库?

linux - 如何从Linux中的文件中获取两列?

linux - 为什么sed会匹配组外的东西作为组的一部分?

bash - 为什么我的终端不能正确输出 unicode 字符?

postgresql - 即使 Kubernetes Pod 被杀死,如何保持长期连接处于事件状态?