[Batches] shell script to modify the extension === modifyExtension.sh

Premise: the need to switch to the need to batch modify the directory extensions, run the script

[root@VM_0_10_centos shellScript]# cat modifyExtension.sh 
#!/bin/bash
# Write batch script to modify the extension, such as a batch file to modify the txt file to doc 
# When executing the script, you need to add parameters to the script location
# Script name txt doc (txt extension can be modified to doc)
if [ $# -eq 0 -o $# -eq 1 ];then
    echo " [Usage]: ./modifyExtension.sh extension after extension modifications to be modified " 
    Exit 0
be
for I in . * $ `LS . 1 `
 do 
    # {$ I %} Usage Reference: HTTPS: // blog.csdn.net/lihonghai2392/article/details/77868445 
    # $ { var %} variable tail deleted character (string ). " % " After the string, but you can also use regular match. I {% $. * } I string after the variable is deleted
    mv $i ${i%.*}.$2
done
echo " modified successfully! "

 

Guess you like

Origin www.cnblogs.com/HeiDi-BoKe/p/11669600.html