Linux bash脚本中未正确显示环境变量
试图添加一个名为abc的数据库,但postgresql却创建了一个名为NEW_database的数据库Linux bash脚本中未正确显示环境变量,linux,bash,psql,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
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";'
与:
问题是shell变量没有在单引号内展开。如果要展开shell变量,请使用双引号
psql -U postgres -c "create database \"$NEW_DATABASE\";"