So I have left a process running on my Mac over the past couple of days to get me a list of all *.class files on my Time Machine backup drive. I finally have a list, and it looks something like this:
./2009-01-21-015517/Macintosh HD/Users/mike/NWL/AxisTester2/build/classes/axistester2/mdWebService/MdWebServices.class
./2009-01-21-015517/Macintosh HD/Users/mike/NWL/AxisTester2/build/classes/axistester2/mdWebService/MdWebServicesLocator.class
This file was created by the command:
# find . -name "*.class" -print | grep NWL > ~/java-class-file-list.txt
Note that it's FAR longer, and that every line in the file has a space in the filename. I want to remove every single file that's mentioned in this file.
So I've created a bash script to read the text file as input and attempt to remove all the .class files:
#!/bin/sh
while read line
do
rm "Backups.backupdb/numbersix/$line";
done < ~/java-class-file-list.txt
However, the space in the "Macintosh HD" portion of the filenames are screwing me up, as confirmed by:
bash-3.2# rm -f "Backups.backupdb/numbersix/2009-01-21-015517/Macintosh HD/Users/mike/NWL/Code/jakarta-struts-1.2.4-src/contrib/struts-el/target/library/classes/org/apache/strutsel/taglib/tiles/ELPutListTagBeanInfo.class"
rm: Backups.backupdb/numbersix/2009-01-21-015517/Macintosh HD/Users/mike/NWL/Code/jakarta-struts-1.2.4-src/contrib/struts-el/target/library/classes/org/apache/strutsel/taglib/tiles/ELPutListTagBeanInfo.class: Operation not permitted
bash-3.2# rm -f "Backups.backupdb/numbersix/2009-01-21-015517/Macintosh\ HD/Users/mike/NWL/Code/jakarta-struts-1.2.4-src/contrib/struts-el/target/library/classes/org/apache/strutsel/taglib/tiles/ELPutListTagBeanInfo.class"
bash-3.2# file "Backups.backupdb/numbersix/2009-01-21-015517/Macintosh\ HD/Users/mike/NWL/Code/jakarta-struts-1.2.4-src/contrib/struts-el/target/library/classes/org/apache/strutsel/taglib/tiles/ELPutListTagBeanInfo.class"
Backups.backupdb/numbersix/2009-01-21-015517/Macintosh\ HD/Users/mike/NWL/Code/jakarta-struts-1.2.4-src/contrib/struts-el/target/library/classes/org/apache/strutsel/taglib/tiles/ELPutListTagBeanInfo.class: cannot open `Backups.backupdb/numbersix/2009-01-21-015517/Macintosh\ HD/Users/mike/NWL/Code/jakarta-struts-1.2.4-src/contrib/struts-el/target/library/classes/org/apache/strutsel/taglib/tiles/ELPutListTagBeanInfo.class' (No such file or directory)
So adding a backslash before the space will fix things and allow my process to run and remove all those pesky compiled Java files. How might I do that inside my bash script operating on each $line?