使用bash脚本循环查询输出

时间:2016-11-09 05:47:52

标签: mysql bash unix

#!/bin/bash
mysql -u root -password << EOF
use runk_prd;
SELECT user_push_token FROM users WHERE user_push_token <> 'NULL' | while read guid user_push_token; do
    echo "pushToken: $user_push_token"
EOF

我试图运行上面的脚本,但是没有返回推送令牌列表,而是给了我以下错误:

mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1064 (42000) at line 2: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'while read guid user_push_token' at line 1

我已在MySQL网络应用程序中测试了该查询,并且工作正常。

1 个答案:

答案 0 :(得分:0)

你错过了管道符号:

试试这个:

val = a.back();
a.pop_back();