I have a shell script that allows a user to add and/or delete files and directories. It's a file Manipulator. The script keeps track of all files that are added or deleted in a log file. I then read the log file line by line and place the files in one of 3 files: dev_deleted.txt, dev_duplicates.txt, or dev_final.txt.
- If a user adds the same file(s) to a directory twice (duplicates) then the file or directory should be listed in dev_duplicates.txt file.
- Any file/directory that is deleted should be listed in dev_deleted.txt
All other files should be listed in dev_final.txt including the filename, first and last char, and length of the file
As you can see in the code below, I read each line in the log file searching for the proper suffix, remove the suffix, and list in dev_deleted.txt, dev_duplicates.txt, or dev_final.txt
dev_deleted.txt works as it should but dev_duplicates.txt and dev_final.txt are not listing the proper files. I ran on my Mac without issues, but now I'm trying to run on Windows 10 OS (I did EOL Conversion to UNIX) and the last case is giving me issues. Can someone help?
I've tried searching for syntax errors
6)
echo "List filesystem directory artifacts"
touch $basedir/dev_final.txt $basedir/dev_deleted.txt $basedir/dev_duplicates.txt
while IFS= read -r line
do
#echo "$line"
if [[ $line == *"-removed" ]]; then
fileName=${line%-*}
echo "$fileName" >> $basedir/dev_deleted.txt
elif [[ $line == *"-new" ]]; then
fileName=${line%-*}
echo "$fileName" >> $basedir/dev_duplicates.txt
else
fileName=${line}
first=${fileName:0:1}
nameLength=${#fileName}
last=${fileName:$nameLength-1}
echo "$fileName, first char:$first, last char:$last, length:$nameLength" >> $basedir/dev_final.txt
fi
done < "$logFile"
;;
esac
done
Files with the -new suffix should be listed in dev_duplicates.txt, files with a -removed suffix should be listed in dev_deleted.txt, and all other files (weren't deleted or duplicate) should be listed in dev_final.txt including the filename, first and last char, and length of the file