Linux Bash脚本grep错误

时间:2018-04-05 19:34:20

标签: linux bash grep

所以我和我的教授在这方面工作了大约2个小时,无法弄清问题是什么,所以我希望有人能看到我们错过的东西。

Enter the sting to delete the files that contain it:
pizza
/home/hopper/z#/CSCI/CSCI330/Assignments/assign4/smith.txt 
/home/hopper/z#/CSCI/CSCI330/Assignments/assign4/data2.txt 
/home/hopper/z#/CSCI/CSCI330/Assignments/assign4/jones2.txt 
/home/hopper/z#/CSCI/CSCI330/Assignments/assign4/cleaner.sh 
/home/hopper/z#/CSCI/CSCI330/Assignments/assign4/jones.txt 
/home/hopper/z#/CSCI/CSCI330/Assignments/assign4/data.txt
String is pizza
File is /home/hopper/z#/CSCI/CSCI330/Assignments/assign4/smith.txt
grep: pizza: No such file or directory
String is pizza
File is /home/hopper/z#/CSCI/CSCI330/Assignments/assign4/data2.txt
grep: pizza: No such file or directory
String is pizza
File is /home/hopper/z#/CSCI/CSCI330/Assignments/assign4/jones2.txt
grep: pizza: No such file or directory
String is pizza
File is /home/hopper/z#/CSCI/CSCI330/Assignments/assign4/cleaner.sh
grep: pizza: No such file or directory
/home/hopper/z#/CSCI/CSCI330/Assignments/assign4/cleaner.sh:                                              
grep –q "$searchstring"  "$file"
String is pizza
File is /home/hopper/z#/CSCI/CSCI330/Assignments/assign4/jones.txt
grep: pizza: No such file or directory
String is pizza
File is /home/hopper/z#/CSCI/CSCI330/Assignments/assign4/data.txt
grep: pizza: No such file or directory

当我选择2时,我会看到grep并收到此错误消息并附上我的疑难解答消息。

filename = 'address1_203.png'
img = Image.open(cam_img+filename)

ocr_out = ocr.image_to_string(img, lang='por', config='-psm 7')

print(ocr_out)

Grep在BASH脚本之外也可以使用绝对路径。测试了if语句,如果我取出-eq它确实正常工作,因为它读取grep确实成功运行只是找不到目录。据我所知,它忽略了我的文件,而是使用字符串搜索作为目录。

1 个答案:

答案 0 :(得分:3)

grep的'-q'参数的破折号部分是一个特殊的非ascii字符,可能是UTF-8中的一个短划线,我看起来并不太难。 Grep不会将en-dash解释为启动选项并在文件列表中搜索字符串'-q'。 'pizza'在文件列表中。

如果您从网页或Word文档中复制代码,则很容易发生这种情况。无论如何,删除-q并重新键入它,你的脚本应该更好。