I am trying to pass a regular expression as a parameter. What should I fix in my code?
My goal is to send find
and the regular expression string, then use grep
on the parameter so I can do whatever I want with what grep
finds (which is print the count of occurrences).
This is what I send:
$ ./lab12.sh find [Gg]reen
Here's my bash code:
if [[ "$1" == "find" ]]
then
declare -i cnt=0
for file in /tmp/beatles/*.txt ; do
if [[ grep -e $2 ]] //problem is here...
then
((cnt=cnt+1))
fi
done
echo "$cnt songs contain the pattern "$2""
fi