使用 shell 脚本重命名文件夹中的文件

Renaming files in folder using shell script

我已经下载了一个视频播放列表,并想使用一个名为 android 播放列表的文件来组织它们。例如:第一个标题为 "Introduction to Android.mp4" 的文件,我必须将其重命名为 1.mp4 。我不知道 perl 或 unix,但到目前为止我已经设法编写了这段代码:

`IFS=''
c=0
d=0
e=1
while read line
 do
     d=`expr $c % 4`
     if [ $d == 0 ]
     then
     echo $line
     rename -n `s/${line}.mp4/${e}.mp4/` *.mp4
     e=`expr $e + 1`
     fi
     c=`expr $c + 1`
done < Android\ playlist`

但这给出了错误:

Bareword found where operator expected at (eval 1) line 1, near "3rd"
    (Missing operator before rd?)
syntax error at (eval 1) line 1, near "3rd Party "
LocationEntry Solution - Developing Android Apps
ren.sh: line 11: s/LocationEntry Solution - Developing Android Apps.mp4$/243.mp4/: No such file or directory
Bareword found where operator expected at (eval 1) line 1, near "3rd"
    (Missing operator before rd?)
syntax error at (eval 1) line 1, near "3rd Party "
SQLiteOpenHelper onUpgrade() method - Developing Android Apps
ren.sh: line 11: s/SQLiteOpenHelper onUpgrade() method - Developing Android Apps.mp4$/244.mp4/: No such file or directory
Bareword found where operator expected at (eval 1) line 1, near "3rd"
    (Missing operator before rd?)
syntax error at (eval 1) line 1, near "3rd Party "
JUnit testing - Developing Android Apps
ren.sh: line 11: s/JUnit testing - Developing Android Apps.mp4$/245.mp4/: No such file or directory
Bareword found where operator expected at (eval 1) line 1, near "3rd"
    (Missing operator before rd?)
syntax error at (eval 1) line 1, near "3rd Party "
InsertReadDbTest - Developing Android Apps
ren.sh: line 11: s/InsertReadDbTest - Developing Android Apps.mp4$/246.mp4/: No such file or directory
Bareword found where operator expected at (eval 1) line 1, near "3rd"
    (Missing operator before rd?)
syntax error at (eval 1) line 1, near "3rd Party "
InsertReadDbTest Solution - Developing Android Apps
ren.sh: line 11: s/InsertReadDbTest Solution - Developing Android Apps.mp4$/247.mp4/: No such file or directory
Bareword found where operator expected at (eval 1) line 1, near "3rd"
    (Missing operator before rd?)
syntax error at (eval 1) line 1, near "3rd Party "
Simplify Tests - Developing Android Apps
ren.sh: line 11: s/Simplify Tests - Developing Android Apps.mp4$/248.mp4/: No such file or directory

请帮帮我。谢谢!

rename -n `s/${line}.mp4/${e}.mp4/` *.mp4

应该是

mv "${line}.mp4" "${e}.mp4"