#!/bin/sh
if [ ! $1 ]; then
echo need dist directory parameter
exit 1
fi
original='oldWord'
newvalue='newWord'
changename() {
name=$1
ss=`echo $name |grep $original`
if [ $ss ]; then
echo changename: $name
echo $name > name.txt
sed -i '' "s/$original/$newvalue/g" name.txt
newname=`cat name.txt`
mv $name $newname
fullpath=$newname
fi
}
getfile(){
for e in `ls $1`
do
fullpath=$1/$e
changename $fullpath
echo $fullpath
if [ -f $fullpath ]; then
sed -i '' "s/$original/$newvalue/g" $fullpath
elif [ -d $fullpath ]; then
getfile $fullpath
fi
done
}
read -p "Are you want to change filecontent?[Y]:" flag
if [ "$flag" == "Y" ]; then
cd $1
getfile .
# rm -rf name.txt
fi
1.将此代码存为test.sh文件,赋执行权限:chmod 7