我已經下載了一個視頻播放列表,並且想要使用名爲android播放列表的文件來組織它們。例如:第一個標題爲「Android.mp4簡介」的文件,我必須將它重命名爲1.mp4。我不知道Perl或UNIX,但我設法到目前爲止編寫代碼:使用shell腳本重命名文件夾中的文件
`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
請幫助我。謝謝!
嘗試使用雙引號,而不是反引號這個:'重命名-n 「S/$ {}行的.mp4/$ {E} .MP4 /」 * .mp4' – tivn
爲什麼問題是perl標籤? –
因爲重命名使用Perl表達式和雙引號不起作用! –