Quantcast
Channel: Prevent parameter expansion in shell script - Ask Ubuntu
Viewing all articles
Browse latest Browse all 3

Prevent parameter expansion in shell script

$
0
0

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.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>