尝试添加名为 abc 的数据库,但 postgresql 创建了一个名为 NEW_DATABASE 的数据库。
export NEW_DATABASE=abc
psql -U postgres -c 'create database "$NEW_DATABASE";'
省略双引号会出错
ERROR: syntax error at or near "$"
LINE 1: create database $NEW_DATABASE;
最佳答案
替换:
psql -U postgres -c 'create database "$NEW_DATABASE";'
与:
psql -U postgres -c "create database \"$NEW_DATABASE\";"
问题是 shell 变量没有在单引号内展开。如果要扩展 shell 变量,请使用双引号。
关于linux - 环境变量未在 bash 脚本中正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48678717/