加if判斷這樣 不滿足條件的就不會去處理。或者處理過的就不會再處理。
${i%%.*} 取文件名
${i#*.} 取擴展名
純小寫字母的轉大寫:
復制代碼代碼如下:
for i in * ; do exp=${i#*.};o=${i%%.*}; if [[ $o =~ ^[a-z]+$ ]];then mv $i $(echo $o|tr [a-z] [A-Z]).$exp; fi; done
連同擴展名:
復制代碼代碼如下:
for i in * ; do exp=${i#*.};o=${i%%.*}; if [[ $o =~ ^[a-z]+$ ]];then mv $i $(echo $o|tr [a-z] [A-Z]).$(echo $exp|tr [a-z] [A-Z]); fi; done
小寫字母開頭
復制代碼代碼如下:
for i in * ; do exp=${i#*.};o=${i%%.*}; if [[ $o =~ ^[a-z] ]];then mv $i $(echo $o|tr [a-z] [A-Z]).$exp; fi; done
連同擴展名:
復制代碼代碼如下:
for i in * ; do exp=${i#*.};o=${i%%.*}; if [[ $o =~ ^[a-z] ]];then mv $i $(echo $o|tr [a-z] [A-Z]).$(echo $exp|tr [a-z] [A-Z]); fi; done