3
0
When at the command line, I find that I have to type out this command very often:
find . -iname "*php" -exec grep -H query {} \;
I'd love to set up an alias, script, or shortcut to make it work easier. I would like to do something like:
mysearch query ("*php") (.)
It would be great if the command could accept three arguments, in reverse order:
query string, file name expression, directory
If the second two arguments were omitted they would default to not being included, and the current directory.
Finally, the icing on the cake would be that if additional variables were included (4th, 5th, 6th...) they would be injected as additional arguments for the find command (like I could say -type d) at the end.
Attempted code
I tried the example below, but I'm still having trouble setting default values. What am I doing wrong?
#!/bin/bash c=${param1+\.} b=${param2+\*} a=${param3+test} find $c -iname $b -exec grep -H $a {} \;
I'm having trouble setting up default values, even after reading the documentation. Any tips? – cwd – 2011-04-06T00:19:49.227
I edited my answer to show how to do defaults. (you need a :- instead of a +). – beatgammit – 2011-04-06T02:48:35.300