尝试使用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;
答案 0 :(得分:1)
替换:
psql -U postgres -c 'create database "$NEW_DATABASE";'
使用:
psql -U postgres -c "create database \"$NEW_DATABASE\";"
问题是shell变量不会在单引号内扩展。如果要扩展shell变量,请使用双引号。