I wrote a function in a Bash script shell to search for a Linux tree for file names matching a pattern containing a regular expression with color highlighting:
function ggrep {
LS_="ls --color {}|sed s~./~~"
[ -n "$1" -a "$1" != "*" ] && NAME_="-iname $1" || NAME_=
[ -n "$2" ] && EXEC_="egrep -q \"$2\" \"{}\" && $LS_ && egrep -n \"$2\" --color=always \"{}\"|sed s~^B~\ B~" || EXEC_=$LS_
FIND_="find . -type f $NAME_ -exec sh -c \"$EXEC_\" \\;"
echo -e \\e[7m $FIND_ \\e[0m
$FIND_
}
eg. ggrep a*lists all files starting with aunder the current directory tree,
and ggrep a* xlists of files starting with aand containingx
When I run it, I get:
find: missing argument to `-exec'
although I get the correct output when I copy and paste the output of a string using "echo" to the terminal. Can someone please tell me what I did wrong?
-, , ggrep * x , x, * , \* '*'. ? !