我正在测试一些bash代码并获取错误,因为我正在阅读最后一行文件并将其与另一行进行比较:
#!/bin/bash
NEW_EVENT_TAIL=`echo tail -1 new_events.txt`
EXISTING_EVENT_TAIL=`echo tail -1 new_events.txt`
if ["$NEW_EVENT_TAIL"="$EXISTING_EVENT_TAIL"];
then
echo "in list"
else
echo "not in list"
fi
基于此代码,并使用完全相同的文件,我希望列表中的""打印。相反,"不在列表中#34;打印出来。我收到的消息:
-bash: [tail -1 new_events.txt=tail -1 new_events.txt]: command not found
答案 0 :(得分:2)
只需删除' echo':
import csv
import MySQLdb
db = MySQLdb.connect( host = "dbname.description.host.com",
user = "user",
passwd = "key",
db = "dbname")
cursor = db.cursor()
query = 'INSERT INTO table_name(column,column_1,column_2,column_3)
VALUES(%s, %s, %s, %s)'
csv_data = csv.reader(file('file_name'))
my_data = []
for row in csv_data:
my_data.append(tuple(row))
cursor.executemany(query, my_data)
cursor.close()
并使用以下内容更改if:
tail -1 new_events.txt
整体脚本
if [ "$NEW_EVENT_TAIL" = "$EXISTING_EVENT_TAIL" ];