我有一个bash脚本时,在bash中为sqlite3查询结果分配变量名称如下
#!/usr/bin/env bash
cd /Users/amar/Documents/ThesisCode/CEP_codes/mqtt-receiver
sqlite3 database <<EOF
SELECT sum(detection_time - generation_time)/count(*) from mobile_cep_data;
SELECT ((max(detection_time)- min(detection_time))*1000)/count(*) from mobile_cep_data;
EOF
它给我结果
15
12
如何获得结果
latency = 15
thoughput = 12
答案 0 :(得分:2)
替换
<<EOF
与
<<EOF | sed '1s/^/latency = /;2s/^/thoughput = /'
答案 1 :(得分:2)
@ Cyrus的答案很好,并展示了一种有用的技巧,因此我赞成它,但我想指出你也可以这样做:
sqlite3 database <<EOF
SELECT 'latency = ',
sum(detection_time - generation_time)/count(*) from mobile_cep_data;
SELECT 'thoughput = ',
((max(detection_time)- min(detection_time))*1000)/count(*) from mobile_cep_data;
EOF