改为:
${filename/.dat/$BKUP_DATE.dat}
连带着后缀名一起替换就不会有问题了。前提是,你的后缀名一定是dat
1、假设你有一堆文件要改名列表2、例如
#!/bin/sh
cd ./sh
ymd=`date +%Y%m%d`
max=`find . -type f -name '*.sh'|wc|awk '{print $1}'`
x=(`seq -f %02g 1 ${max}`)
i=0
for file in `ls *.sh`do
file1=$(echo $file|awk -F. '{print $1}')
newfile=$file1-$ymd-${x[$i]}.sh
echo $file $newfile
/bin/mv $file $newfile
((i++))
done
3、执行
199.sh 199-20180206-01.sh
204.sh 204-20180206-02.sh
27.sh 27-20180206-03.sh
28.sh 28-20180206-04.sh
76.sh 76-20180206-05.sh
#!/bin/bashread -p "please enter the date: " date
if [[ $date =~ "[0-9]{2}/[0-9]{2}/[0-9]{4}" ]]
then
echo "today is:${date:0:2} month is:${date:3:2} year is:${date:6:4}"
else
echo "wrong date"
fi
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)