2014-02-25 45 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)'開頭呢? –