Convert my bash command into a bashrc function and pass argument

bash, command, linux, shell

Solution

Bash won't substitute variables in single quotes. Try this:

function findit() {  
  { find . -name "*$1*";  
    grep -irl "$1" .;  
  } | sort -u  
}  
export -f findit  

Problem

I've got a sweet bash command to find key phrases in files and filepaths, thanks to @ezod here. I'm trying to turn it into a function in my bashrc, but it doesn't generate the same result. I'm guessing it's related to back-to-back curly brackets that I need to escape or use an alternative method? Works: ``` { find . -name '*keyword*'; grep -irl 'keyword' .; } | sort -u ``` Does not work in bashrc: ``` function findit() { { find . -name '*$1*'; grep -irl '$1' .; } | sort -u } export -f findit $ findit keyword ```

Original source