I'm trying to write a script which identifies name groups from the filenames of photos exported out of the Photo app, creates directories out of those filenames, and then puts the same photos into their corresponding directories. E.g. "Oranges1.jpg" and "Oranges5.jpg" get put into a directory labeled "Oranges".
The first part I have no trouble with. The second part, with moving the files into the directories, has me stumped. I have the files in one folder on my desktop, I created the new folders in a separate one, and I'm using this variable in a for loop:
SEARCH=$(ls /Users/ithomas/Desktop/files/ | grep ${DIR#*directories/})
Where $DIR is just the name of each newly created directory I'm moving everything to. I've verified that my $SEARCH variable compares the filenames and folder names effectively, but the output always looks like this:
Fifth Grade Elements of Art - 1 of 2.jpeg
which means I can't pipe it into mv to send it to the appropriate folder because there are no escape characters.
Is there a way to reintroduce the escape characters to the stdout or is there another method I might use?