使用 <<EOF 时,将变量名称分配给 bash 中的 sqlite3 查询结果
Assign variable name to sqlite3 query result in bash when <<EOF is used
我有一个bash脚本如下
#!/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
替换
<<EOF
和
<<EOF | sed '1s/^/latency = /;2s/^/thoughput = /'
@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
我有一个bash脚本如下
#!/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
替换
<<EOF
和
<<EOF | sed '1s/^/latency = /;2s/^/thoughput = /'
@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