I have a Bash Script that is intended to locate files that are created on a specific date. It is working as bellow.
#!/bin/bash
LOCATION="/tmp/testfiles"
DATE="Jan 10"
COMMAND="ls -l ${LOCATION} | grep '${DATE}'"
for FILE in `eval $COMMAND`
do
echo $FILE
done
It is locating the file that I expect it to
-rw-rw-rw- 1 root root 9485 Jan 10 10:00 test01.log
But the bash for loop is looping through all of the fields of the ls -l command so I am ending up with
-rw-rw-rw-
1
root
root
9485
Jan
10
10:00
test01.log
Which I don't want. Is it possible to extract the filename from an ls -l command in order to keep the loop from processing all of the fields.
I can't use just ls in this case because I need to know the date in order for the grep to work.
PS. I know it's not recommended to store commands into variables but I need it like that for now, I will probably change it at a later stage.