我希望从我编写的 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/