コマンドライン引数として与えられた、現在の作業ディレクトリ内のすべてのファイルの名前を "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エラーを理解していません。
をhttp://tldp.org/LDP/abs/html/)。 –