I would like to create a script on SUSE Enterprise Linux, it first asks for a string (representing a date) and then search for all files in a certain directory which contains the string in its filename. If there is an empty input, todays date should be used.
I now have this:
read -p "Send files from date (MM-DD-YYYY) : " fromdate
if [[ -z ${fromdate// } ]]
then
echo "Empty input"
fromdate=$(date +%m-%d-%Y)
fi
echo "Input: $fromdate"
cd /path/to/directory
while IFS= read -r -d '' file ; do
echo "$file"
done < <(find . -maxdepth 1 -name "*$fromdate*" -print0)
When I enter a date, it works fine, for empty input, I get an error:
fromdate: command not found
The input is still empty, and all files are displayed. What could be my mistake? Should I use the 'let'-command?
find
directly? – Wildcard Nov 18 '15 at 15:09fromdate
and=
. – Mikel Nov 18 '15 at 15:16