Joe*_*her 4 linux bash shell command
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
Run Code Online (Sandbox Code Playgroud)
Does not work in bashrc:
function findit() {
{ find . -name '*$1*';
grep -irl '$1' .;
} | sort -u
}
export -f findit
$ findit keyword
Run Code Online (Sandbox Code Playgroud)
Bash 不会用单引号替换变量。尝试这个:
function findit() {
{ find . -name "*$1*";
grep -irl "$1" .;
} | sort -u
}
export -f findit
Run Code Online (Sandbox Code Playgroud)