#!/bin/sh declare -A myMap myMap["test.ts"]="yw_0001.ts" //需要改名的map function getfile(){ echo $1 for file in $1/* do if test -f $file then echo $file arr=(${arr[*]} $file) if [ "${file##*.}"x = "ts"x ];then //扩展名为.ts if [ ! ${myMap[${file##*/}]} ]; then echo ${file##*/}" NO VALUE " else echo "CHANGED FILENAME: "${file%/*}"/"${myMap[${file##*/}]} //查出来的是全路径,进行拆分与拼接 mv $file ${file%/*}"/"${myMap[${file##*/}]} fi fi else getdir $file fi done } getfile /data/media