我有下面的代碼,它應該將當前工作目錄中的所有文件重命名爲「basenameCOUNTextension」,作爲命令行參數給出。將前輩零加到一個整數而不在bash中強制轉換
base=$1
ext=$2
c=1
for file in *
do
if [ c > 100 ]; then
mid=$(printf "%03d" $c)
elif [ c > 10 ]; then
mid=$(printf "%03d" $c)
else
mid=$(printf "%03d" $c)
fi
if [ -e ./"$file$mid$ext" ]
then
continue
fi
mv "$file" "$base$mid$ext"
((c++))
done
這將是一個目錄中的內容一例這個腳本的運行成功後:
$ renumber 25thAnniversary jpeg
then the resulting files should have names like:
25thAnniversary001.jpeg, 25thAnniversary002.jpeg, 25thAnniversary003.jpeg, etc.
處理「001」,「939」等是我的問題。我不確定printf是要走還是隻是一些條件。
這是我的編譯錯誤:
renumber.sh: line 12: =c: command not found
mv: cannot move â(FILEPATH)â to ââ: No such file or directory
什麼是我的問題嗎?第12行對我來說似乎不是一個語法錯誤,我不瞭解mv錯誤。
我推薦一兩個小時用[**高級Bash腳本編程指南**]( http://tldp.org/LDP/abs/html/)。 –