I need to rename a file from "some string[blah].srt" to "some.string.srt";

I use:

mv -v "$file" "$newfile.srt"

$newfile is $file with dots instead of spaces.

I get the following error:

mv: rename dir1/Some string[blah].srt* to dir1/Some.string.srt: No such file or directory

Here is the variable values and the dir content:

dir content:
total 715368
-rwxr-xr-x  1 Dahan  staff    43K Nov 29  2012 Some string S01E12[blah].srt*
-rw-r--r--  1 Dahan  staff   349M Mar 26 20:42 Some.string.S01E12.avi
newfilename: /Users/Dahan/dir1/Some.string.S01E12.srt
file: /Users/Dahan/dir1/Some string S01E12[blah].srt*
mv: rename /Users/Dahan/dir1/Some string S01E12[blah].srt* to    /Users/Dahan/dir1/Some.string.S01E12.srt: No such file or directory

Somehow if I remove the [blah] part from the file it works OK.

Any idea what did I do wrong?

有帮助吗?

解决方案

The problem apparently is parsing ls

It worked for the .avi file because it does not have execute permissions, so ls -F does not append an asterisk to the filename.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top