Unable to execute grep command in script while passing the string to be searched as variable

Viewed 34

I am trying to run following script but unable to run the find/grep command successfully as the variable in grep command is causing an issue. Can someone please help what wrong I am doing while passing the variable in grep. Basically I am reading an input from the file and passing that in grep.

#!/bin/bash
DATE_FOLDER='20220922'
while IFS= read -r line
do 
name="$line"
echo "Name read from file - $name"
echo $name
find /ABC/XXX/$DATE_FOLDER*/ -type f -exec grep -l "'${name}'" {} \; >> fileNameList.txt

done < TestInput.txt
sort -u fileNameList.txt >> finalNameList.txt
0 Answers
Related