【发布时间】:2013-03-06 08:53:31
【问题描述】:
如何像下面的脚本一样在 bash 变量上提取标量 postgresql 值?
dbname="testlauf"
username="postgres"
vartest='psql -c -d $dbname -U $username -h localhost -p 5432 "SELECT gid FROM testtable WHERE aid='1';"'
echo "$vartest"
我尝试了几种不同的作品,但似乎没有任何效果。提前致谢。
【问题讨论】:
-
对于命令替换,您必须使用反引号 (
`) 或$()。单引号 (') 不行。 -
谢谢。但不幸的是,即使 vartest=
$(psql -c -d testlauf -U postgres -h localhost -p 5432 "SELECT gid FROM testtable WHERE aid='1';")也无法做到这一点......它给了我“sytnac error near or at "-d"” 我也用 dbname 尝试过...... -
标签: bash postgresql variables