linux - 环境变量未在 bash 脚本中正确显示

标签 linux bash psql

尝试添加名为 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/

相关文章:

php - CentOS 服务器编译发布 APK

linux - 如何删除基于另一个文件的行?

bash - Shell 脚本将所有输出转储到一个文件

bash - 获取 "sed error - illegal byte sequence"(在 bash 中)

java - 使用 Java exec 的额外 psql 命令行参数

linux - rdiff 备份命令中的目录用于什么

linux - 组的所有命令都应该成功或无

python - 减少将 POStgreSQL 表引入具有 500000 行的 Pandas 的执行时间的替代方法?

postgresql - 无法在 Postgresql 中编辑 pg_hba.conf 文件

python - 如何在输入流中播放声音