我试图编写一个bash脚本来搜索存储在某个位置的文件中的用户定义字符串,我想扫描包含某些字符串的位置中的所有文件," log"在这个例子中
#!/bin/bash
&fname= "/path/logfile1"* #1
read -p "Searching for: " pattern #2
if [[ $fname == "log"* ]]; #3
then
result=$(grep -i "$pattern" "$fname")
echo "$result" #4
fi
1 variable consisting of a path to a directory where all the files contain string of"log" in their names
2 reading user defined pattern to be found in the above files
3 checking if file/files name/s contain/s string "log"
4 if the above met display lines containing desired string