I hava problem with bash srcipt that removes all files ( with name given
in $1 ) in current dir and subdirectories .
The problem is that the script don't see all subdirectories and when
I try to run it in my home dir the srpit display strange message .
Code:
#!/bin/sh
# this sript remove file from current dir and his subdir ..
remove_file()
{
#########
#echo "$1" # $1- current dir , $2 - filename
#echo "$2"
#########
if [ "$#" -eq 2 ] ; then # $1 and $2
for file in *
do
if [ $file = "$2" ] && [ -f $file ] ; then
echo
echo "Remove : ${1}/${file} "
#rm -f ${1}/${file} # removing ...
elif [ -d $file ] ; then
local directory=`pwd` # current dir
echo
echo "IN : ${directory}/${file} "
( cd $directory/${file} ; remove_file $directory/${file} $2 ) # recursve call
else
return 0
fi
done
else
return 0
fi
}
remove_file `pwd` $1 # $1 is the filename that we want to remove