I'm trying to rename a bunch of files which contain spaces in them, getting rid of the spaces. I thought I found the correct bash command:
for f in *.txt; do mv \"$f\" ${f/ /}; done
However, this gives the error, "mv: target is not a directory" for each file. If I replace 'mv' with 'echo mv' in the command, it prints the proper mv command for each file, and if I type any of those mv commands individually, they work. For example, if I have 2 files, "a .txt", and "b .txt", and run the command above, I get:
mv: target 'a.txt' is not a directory
mv: target 'b.txt' is not a directory
If I type the command:
for f in *.txt; do echo mv \"$f\" ${f/ /}; done
I get:
mv "a .txt" a.txt
mv "b .txt" b.txt
I've found another way to do this, using "rename", but I would like to know why this doesn't work.