亲测有效
改一个
[root@localhost test]# ls
feng.txt liu.txt xiao.txt
[root@localhost test]# filename=liu.txt
[root@localhost test]# echo $filename
liu.txt
[root@localhost test]# echo $filename|cut -d . -f1
liu
[root@localhost test]# echo “
echo $filename|cut -d . -f1
.jpg”
liu.jpg
[root@localhost test]# mv $filename
echo $filename|cut -d . -f1
.jpg
[root@localhost test]# ls
feng.txt liu.jpg l xiao.txt
批量改
[root@localhost liuxiao]# ls
feng.txt liu.txt xiao.txt
[root@localhost liuxiao]# vim 11_9.sh
[root@localhost liuxiao]# cat 11_9.sh
#!/bin/sh
cd /liuxiao
for filename in
ls|grep \"txt$\"
do
mv $filename
echo $filename|cut -d . -f1
.jpg
done
[root@localhost liuxiao]# sh 11_9.sh
11_9.sh: line 2: cd: /liuxiao: No such file or directory
[root@localhost liuxiao]# ls
11_9.sh feng.jpg liu.jpg xiao.jpg
[root@localhost liuxiao]#
求关注,谢谢。