I often have to do a recursive search in files. Tired of typing the whole "find/grep" combination all the time, I just created a script with the following line:
find . -name $1 -exec grep $2 {} + 2>/dev/null
The idea is that I should be able to run it as, for example:
myfind '*' hello
The problem is, when '*'
gets passed into the script, the script is expanding it to each file in the directory.
I tried putting a quote around $1
:
find . -name '$1' -exec grep $2 {} + 2>/dev/null
However, this turns $1
into a literal string.
Would appreciate your help in finding the right syntax. Must be something simple that I am missing.