I have tried different variations of the following but nothing seems to work. Basically when find gets executed nothing appears to happen. Below I present my bash function code and my output when I run it.I am interested in understanding what happens with the code below and why itdoesn't behave as when I type the command explicitly.Also I got told I will not have access to rgrep in some boxes I will be working on and thus I try this approach for a generic solution to grepping for code etc.function findin() {if [ -z $1 ] ; then    echo Usage: findin <file pattern> <<grep arguments>>    return 1fifIn[1]=$1shiftfIn[2]=$@echo -- ${fIn[1]}echo -- '${fIn[2]}'find -type f -name '${fIn[1]}' -print0 | xargs -0 grep --color=auto ${fIn[2]}}And the output is:$ lsServer.tcl  Server.tcl~  test.cfg  vimLearning.txt$ find -type f -name '*.txt' -print0 | xargs -0 grep --color=auto charx      deletes char under cursor. NNx deletes NN chars to RHS of cursor.r      type r and the next char you type will replace the char under the cursor.$ findin '*.txt' char-- *.txt-- 'char'
Problem with find and variables
bash
The pattern you probably intended to use was *.txt, but you are telling find -name to use '*.txt', including the single quotes, which does not match any files.  The expansion works as follows:On the command line, when you type $ find -name '*.txt'your shell sees '*.txt' is quoted, so it strips the quotes and passes the contents, *.txt, to find.In the function,find -name '$var'the shell expands $var to *.txt.  Since the expansion occurred within double-quotes, the shell strips the double quotes and passes the contents, '*.txt', to find.The solution is simple: remove the single quotes in find -name '$var'.I touched up your function for you:findin () {    if (( $# < 2 )); then        >&2 echo Usage: findin <file pattern> <grep arguments ...>        return 1        fi                   pattern=$1                   shift    printf '%s\n' -- ${pattern}    printf '%s ' -- $@    echo    find -type f -name ${pattern} -print0 |             xargs -0 grep --color=auto $@}     