【发布时间】:2023-03-21 18:45:01
【问题描述】:
我正在尝试使用 grep 命令,但是我不知道如何在“grep $word $file”之后继续,或者即使它会起作用。我需要做的是获取程序,以便在他们输入一个单词和一个文件后,如果该单词在文件中,则程序会回显“您输入的单词在您输入的文件中”。而且我还需要它来打印“对不起,您输入的单词不在您输入的文件中”,如果您能提供帮助,那将非常有帮助,谢谢
#!/bin/bash
echo "Welcome what please type in what you would like to do!"
echo "You can:"
echo "Search for words in file type (S)"
echo "Quit (Q)"
read option
while $option in
do
S) echo "What is the name of the file you would like to search for?"
read file
echo "What word would you like to find in the file?"
read word
grep $word $file
Q) echo "Goodbye!"
exit
esac
done
【问题讨论】:
标签: linux string bash grep find