2014-02-25 20 views
1

如何在postgres psql UPDATE命令中分配参数/参数。我试着用下面的命令。bash脚本:如何使用postgres psql和UPDATE语句更新数据库表

c="openssl rand -base64 6" 
ab=eval $c 
psql -d db_name -c "UPDATE table_name SET password = '$ab' WHERE name = 'cde'" 

上面的命令将更新科拉姆“密码”表“表名”为“”(空字符串引号),而不是更新的价值“$ AB”。 '$ ab'是一个字符串。

任何人都可以帮忙吗?

回答

1

这是它的工作方式:

c="openssl rand -base64 6" 
ab=`$c` 
psql -d db_name -c "UPDATE table_name SET password = '$ab' WHERE name = 'cde'" 
+1

完美的作品。感谢您的更正。 – user3346016

+0

为什么不直接写'ab = $(openssl rand -base64 6)'开头呢? –