[email protected] 1]# cat mv.sh
#!/bin/bash
For file in ' LS *.jpg '
Do
/BIN/MV $file ' echo ' ${file%finished*}.jpg '
Done
[email protected] 1]# LL
Total 8
-rw-r--r--1 root root 106 Dec 05:33 A.log
-rw-r--r--1 root root from Dec 05:39 mv.sh
-rw-r--r--1 root root 0 Dec 05:34 stu_102999_1_finished.jpg
-rw-r--r--1 root root 0 Dec 05:34 stu_102999_2_finished.jpg
-rw-r--r--1 root root 0 Dec 05:34 stu_102999_3_finished.jpg
-rw-r--r--1 root root 0 Dec 05:34 stu_102999_4_finished.jpg
[Email protected] 1]# sh mv.sh
[email protected] 1]# LL
Total 8
-rw-r--r--1 root root 106 Dec 05:33 A.log
-rw-r--r--1 root root from Dec 05:39 mv.sh
-rw-r--r--1 root root 0 Dec 05:34 stu_102999_1_.jpg
-rw-r--r--1 root root 0 Dec 05:34 stu_102999_2_.jpg
-rw-r--r--1 root root 0 Dec 05:34 stu_102999_3_.jpg
-rw-r--r--1 root root 0 Dec 05:34 stu_102999_4_.jpg
Ideas:
[Email protected] 1]# k= "Stu_102999_1_finished.jpg"
[Email protected] 1]# echo ${k%finished*}.jpg
Stu_102999_1_.jpg
2. Modify the extension with ${string/%substring/replace}
[[email protected] 201126_02]# ls
1.log 1.sh Camz. HTML ICPC. HTML Leco. HTML WJB. HTML Zshu. Html
Change the suffix to html to th
[Email protected] 201126_02]# vim 1.sh
#!/bin/bash
For f in ' LS *. HTML '
Do
MV $f ' echo ${f/%html/th} '
Done
[Email protected] 201126_02]# sh-x 1.sh
+ + ls Camz. HTML ICPC. HTML Leco. HTML WJB. HTML Zshu. Html
+ for f in ' LS *. HTML "
+ + echo camz.th
+ MV Camz. HTML camz.th
+ for f in ' LS *. HTML "
+ + echo icpc.th
+ MV ICPC. HTML icpc.th
+ for f in ' LS *. HTML "
+ + echo leco.th
+ MV Leco. HTML leco.th
+ for f in ' LS *. HTML "
+ + echo wjb.th
+ MV WJB. HTML wjb.th
+ for f in ' LS *. HTML "
+ + echo zshu.th
+ MV Zshu. HTML zshu.th
[[email protected] 201126_02]# ls
1.log 1.sh camz.th icpc.th leco.th wjb.th zshu.th
Shell batch file renaming