I've got this script which copies files listed in a csv recursively from a main folder. The copying aspect of the script works perfectly. However, I now want to add some error detection functionality. The "if" loop I have added below doesn't work as I would like. I have added a fake file to my csv list for testing purposes, and the script reports that all files have copied successfully, even though one of the files doesn't exist. Could someone suggest how I can get the script to report the file(s) it has not successfully found/copied from the csv and specify the file names? EDIT ** As there are 4000+ files listed in the CSV, I would like the script to print a summary of any copy failures at the end of the script, rather than for each files copied during the process. This would make it easier to identify/summarize any issues.
while IFS=, read -r file rest
do
find $sourcefolder -name "${file}" -exec cp '{}' $destfolder \;
done < $csv
if [ $? -eq 0 ]
then
echo "All files from CSV copied succesfully"
else "File from CSV not copied as not found"
fi