mysql - 在 shell 脚本中将表计数设置为变量..?

标签 mysql bash shell variables ingres

我希望从我编写的 SQL 的“count”变量中返回一个数值。不幸的是,我刚收到一条 Ingres 错误消息。知道我做错了什么吗?

请参阅下面的 shell 脚本代码:

#!/bin/ksh
###############

count=$(sql db_name -s -N "SELECT COUNT(*) FROM temp_table;")

echo "Table count = $count"

请参阅下面的 Ingres 错误:

Table count = INGRES TERMINAL MONITOR Copyright 2008 Ingres Corporation 
E_US0022 Either the flag format or one of the flags is incorrect,
    or the parameters are not in proper order.

预期结果:

Table count = 8

最佳答案

试试这个:

=>|Fri Feb 17|01:51:01|postgres@[STATION]:/var/lib/pgsql> ./test.sh
count ------- 3 (1 row)

=>|Fri Feb 17|01:51:04|postgres@[STATION]:/var/lib/pgsql> cat test.sh
#!/bin/bash

count=$(psql <<EOF
select count(*) from mdn_2 ;
EOF
)
# Prints the result captured from DB
echo $count

=>|Fri Feb 17|01:51:05|postgres@[STATION]:/var/lib/pgsql>

关于mysql - 在 shell 脚本中将表计数设置为变量..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42280841/

相关文章:

php - MySQL查询货币格式

perl - jsvc (tomcat) 在使用反引号运行然后失效时无法正确守护进程

bash - 如何检查 docker daemon 是否正在运行?

linux - 请解释 Linux bash exec 和 ssh-agent 行为

python - 在后台启动程序,并在其中一个程序因退出代码而死亡时立即将其杀死

swift - 在 Swift 中使用模式运行 shell 命令

linux - Bash/expect脚本控制执行

mysql - 使用 Ajax-PDO 的 cleditor 内容不会保存或删除

c# - 如何修复连接字符串错误? con.Open() 抛出 'MySql.Data.MySqlClient.Replication.ReplicationManager'

mysql - 如何通过Node从MySQL中查询数据