# bin/bash!
# 第一种写法.
for file in $(ls ./);
do
if [ -f $file ] && [[ $file == *".py" ]]
then
echo $file is py file.
elif [ -f $file ] && [[ $file == *".txt" ]]
then
echo $file is txt file.
elif [ -d $file ]
then
echo $file is dir.
rm -rf $file
else
echo $file is not file \| dir.
fi
done
# 第二种写法
function file_judge {
if [ $# -ne 1 ]
then
echo param count is not 1.
exit
fi
if [[ $1 == *".py" ]];
then
echo $1 is py file.
elif [[ $1 == *".txt" ]];
then
echo $1 is txt file.
elif [[ $1 == *".sh" ]];
then
echo $1 is shell file.
else
echo $1 is other file.
fi
}
for file in $(ls ./);
do
if [ -f $file ]
then
file_judge $file
elif [ -d $file ]
then
echo $file is dir.
rm -rf $file
else
echo $file is not file \| dir.
fi
done