change all file suffix to other one.
test shell
#!/usr/bin/env bash
function change_suffix() {
oldsuffix=$1
newsuffix=$2
dir=$(eval pwd)
for file in $(ls $dir | grep .${oldsuffix})
do
name=$(ls ${file} | cut -d. -f1)
mv $file ${name}.${newsuffix}
done
echo "change $1 to $2 successd!"
}
#if [ "" = "$1" ];then
#if [ ! -n "$1" ] || [ ! -n "$2" ];then
if [ $# != 2 ] ; then
echo "please input both oldsuffix and newsuffix which you want to change"
exit
else
echo "iiiiiiiiiiiii change $1 to $2 successd!"
#change_suffix
fi
if [ "" = "$1" ] || [ "" = "$2" ] ;then
echo "please input both oldsuffix and newsuffix which you want to change"
else
echo "iiiiiiiiiiiii change $1 to $2 successd!"
#change_suffix
fi
if [ ! -n "$1" ] ;then
echo "you have not input a word!"
else
echo "the word you input is $1"
fi
final:
#!/usr/bin/env bash
function change_suffix() {
oldsuffix=$1
newsuffix=$2
dir=$(eval pwd)
for file in $(ls $dir | grep .${oldsuffix})
do
name=$(ls ${file} | cut -d. -f1)
mv $file ${name}.${newsuffix}
done
echo "change $1 to $2 successd!"
}
if [ $# != 2 ] ; then
echo "please input both oldsuffix and newsuffix which you want to change"
exit
else
echo " change $1 to $2 successd!"
#change_suffix
fi
#if [ "" = "$1" ] || [ "" = "$2" ] ;then
#echo "please input both oldsuffix and newsuffix which you want to change"
#else
#echo " change $1 to $2 successd!"
#exit
##change_suffix
#fi
damn it ,bug..............
should use gloable variable
#!/usr/bin/env bash
oldsuffix=$1
newsuffix=$2
function change_suffix() {
dir=$(eval pwd)
for file in $(ls $dir | grep .${oldsuffix})
do
name=$(ls ${file} | cut -d. -f1)
#echo "$file ${name}.${newsuffix} "
mv $file ${name}.${newsuffix}
done
echo "change ${oldsuffix} to ${newsuffix} successd!"
}
if [ $# != 2 ] ; then
echo "please input both oldsuffix and newsuffix which you want to change"
exit
else
change_suffix
fi
#if [ "" = "$1" ] || [ "" = "$2" ] ;then
#echo "please input both oldsuffix and newsuffix which you want to change"
#else
#echo " change $1 to $2 successd!"
#exit
##change_suffix
#fi

17万+

被折叠的 条评论
为什么被折叠?



