Shell脚本和sqlite3

2024-09-19 23:58:45 发布

您现在位置:Python中文网/ 问答频道 /正文

场景: 我正在尝试一个小的shell脚本程序。在

在这个程序中-我试图查询一个有两个表的数据库。试图得到一个是或不是的答案。在

我使用python脚本从文件中获取的etag = md5sum。在

echo 'select a.hash,b.hashuser, case when a.hash=b.hashuser then "No!" else "yes!" end from tempo b, hashes a where a.hash=b.hashuser and b.hashuser='$etag''

当我试图在屏幕上打印它时,它清楚地显示了etag作为md5sum

但是,如果我试图在数据库中查询它并尝试获取结果。使用下面给出的脚本

^{pr2}$

这是我得到的错误。在

 Error: unrecognized token: "579f0b61cf958a0eea2f60906e6a04a4"

在google上搜索了一下之后,这就是我从这个link找到的解决方案

然后我把它改成${#etag}

echo 'select a.hash,b.hashuser, case when a.hash=b.hashuser then "No!" else "yes!" end from tempo b, hashes a where a.hash=b.hashuser and b.hashuser='${#etag}''

我现在得到的错误是

select a.hash,b.hashuser, case when a.hash=b.hashuser then "No!" else "yes!" end from tempo b, hashes a where a.hash=b.hashuser and **b.hashuser=32**

为什么b.hashuser=32。是我的第一个问题。在

第二个问题:

当我试图使用上述函数查询数据库时:

sqlite3 hashez.db 'select a.hash,b.hashuser, case when a.hash=b.hashuser then "No!" else "yes!" end from tempo b, hashes a where a.hash=b.hashuser and b.hashuser='${#etag}''

我没有得到回复。在

  • 我的问题错了吗。,如果是,为什么我直接在数据库上查询时得到答案?在

对不起,我的英语不好


Tags: nofromhashwhereselectelseyesend
1条回答
网友
1楼 · 发布于 2024-09-19 23:58:45

你在胡说你的报价。在

somecmd 'SELECT ... "'"$etag"'", ...'

注意单引号内的双引号,以及参数替换周围的双引号。在

相关问题 更多 >