Linux 如何编写shell脚本来搜索目录列表中的文本

Linux 如何编写shell脚本来搜索目录列表中的文本,linux,shell,Linux,Shell,我必须通过name check.sh编写一个shell脚本来搜索目录列表中的文本。下面的shell脚本工作正常 find . | xargs grep 'def wander' --color -n str='def wander' find . | xargs grep $str --color -n 但是,在向这个grep传递参数时,没有正常工作 find . | xargs grep 'def wander' --color -n str='def wander' find . |

我必须通过name check.sh编写一个shell脚本来搜索目录列表中的文本。下面的shell脚本工作正常

find . | xargs grep 'def wander' --color -n
str='def wander'
find . | xargs grep $str --color -n
但是,在向这个grep传递参数时,没有正常工作

find . | xargs grep 'def wander' --color -n
str='def wander'
find . | xargs grep $str --color -n
它只接受“def”而不接受“def wander”。我犯了什么错

str='def wander'
find . | xargs grep "$str" --color -n
但是请注意,您可以在不使用
find
命令的情况下获得相同的结果:

grep --color -rn "def wander" .