eric_csm wrote:
#!/bin/bash
for f in `find . -maxdepth 3 -name 'Music 1' -type d`;
do g=`echo $f | sed 's/Music 1$/Music$/'`;
mv -v $f $g;
done
This is the output I get:
mv: rename ./staff0809/acutts/Music to ./staff0809/acutts/Music: No such file or directory
mv: rename 1 to 1: No such file or directory
The error is caused because the 'for' command delimits the entries by space, therefore the first run through f is set to '/path/to/Music' and the second time through f is set to '1'
I don't think for can be used in that way, I personally would use the following style of loop to get around it...
Code:
#!/bin/bash
find . -maxdepth 3 -name 'Music 1' -type d | while read f
do
g=$(echo $f | sed 's/Music 1$/Music$/')
mv -v "$f" "$g";
done
Using the while read loop removes the issue that the for loop caused, however also note that the mv command's options are also space delimited so the $f MUST be in quotes to deal with the space.
This type of loop also has issues (the loop is in a bash sub-shell) but would seem to be suitable in this situation.
I hope this helps