我正在尝试在 shell 脚本中验证更新或选择查询。
比如我的查询是:
update table_name set col_name = 1 where emp_id = '1234'
如果代码将验证第一个词必须是update
,第二个词必须是table_name
,第三个词将是set
。我试图验证,但我无法得到这些东西。
我创建了一个非常简单的 python
脚本,它适用于 v2 和 v3。
将内容复制到filename.py并执行sudo chmod +x filename.py
#!/usr/bin/env python
string = "update table_name set col_name = 1 where emp_id = '1234'"
x = string.split(' ')
if "update" != x[0]:
print("the first word does not contain update, exiting")
exit
else:
print("the first word contains update")
if "update" != x[1]:
print("the second word does not contain table_name, exiting")
exit
else:
print("the second word contains table_name")
if "update" != x[2]:
print("the third word does not contain set, exiting")
exit
else:
print("the third word contains set")
print("we're good to go")
我是一名优秀的程序员,十分优秀!