#!/bin/bash
#文件名 rename.sh
#用途:重命名.jpg和.png文件
count=1;
for img in *.jpg *.png
do
new=image-$count.${img##*.}
mv "$img" "$new" 2> /dev/null
if [ $? -eq 0 ];
then
echo "Renaming $img to $new"
let count++
fi
done
请问红色标记的地方是啥意思哦?
------解决方案--------------------------------------------------------
将"$img"重命名为"$new",把出错消息重定向到/dev/null,即,即使出错也不会有任何提示。
数字的含义:0表示stdin,0表示stdout, 2表示stderror
------解决方案--------------------------------------------------------
${img##*.}是截取img变量从头部直到第一个.的字符串吧。
------解决方案--------------------------------------------------------
是去掉最大前缀.
img=image.jpg
${img##*.}就是jpg
${parameter##word}
Remove Largest Prefix Pattern. The word will be expanded to produce a pattern. The parameter expansion then will result in parameter, with the largest portion of the prefix matched by the pattern deleted.