I am trying to rename a few hundred files based on another file in the same directory. I found a script and with modification I have the following:
while read file; do echo mv "\"${file%/*}/Trailer.mov\"" "\"${file%.*}-Trailer.mov\""; done < <(find . -type f ! -name "Trailer.mov" -name "*.mkv")
It outputs mv commands like so:
mv "./dir1/Trailer.mov" "./dir1/filename-Trailer.mov"
The mv commands do rename the files correctly (if it exists) when I run it manually. When I run the script without echo it gives errors like so:
mv: cannot stat ‘"./dir1/Trailer.mov"’: No such file or directory
This error happens for every single item regardless of the files existence. Whyd does this happen? I am running as root.
mv
command?-name "*.mkv"
echo
input and output.mv
would not work in the shell with theecho
input. It just works with theecho
output. That's whateval
does (in a certain way): It tells the shell: Don't use the input, use the output.