bash 遍历目录
时间:2009-08-07 来源:AppleDragon
#!/bin/bash
function usage {
echo "Usage: ./$0 DIR"
}
recursive () {
first_directory=$1
cd $first_directory
directory_array=(*);
for directory in ${directory_array[@]}; do
if [ -d $directory ] ; then
(( directory_count += 1 ))
recursive $directory
echo In Directory : `pwd`
domywork
cd ..
fi
done
}
function domywork {
for file in `ls *.java`;
do
# do sth
grep 'ltable' $file > /dev/null;
(( a = $? ))
grep 'ismanagingfocus' $file > /dev/null;
(( b = $? ))
grep 'ismanagingfocus = true' $file > /dev/null;
(( c = $? ))
if [ $a -eq 0 ]; then
if [ $b -gt 0 ]; then
echo $directory$file;
fi
if [ $c -eq 0 ]; then
echo $directory$file;
fi
fi
done
}
#check for required parameters
if [ ${#1} -gt 0 ]; then
cd $1
echo "In Directory : `pwd`"
domywork
recursive "$1"
echo "$directory_count directories processed."
else
#print usage information
usage
fi
function usage {
echo "Usage: ./$0 DIR"
}
recursive () {
first_directory=$1
cd $first_directory
directory_array=(*);
for directory in ${directory_array[@]}; do
if [ -d $directory ] ; then
(( directory_count += 1 ))
recursive $directory
echo In Directory : `pwd`
domywork
cd ..
fi
done
}
function domywork {
for file in `ls *.java`;
do
# do sth
grep 'ltable' $file > /dev/null;
(( a = $? ))
grep 'ismanagingfocus' $file > /dev/null;
(( b = $? ))
grep 'ismanagingfocus = true' $file > /dev/null;
(( c = $? ))
if [ $a -eq 0 ]; then
if [ $b -gt 0 ]; then
echo $directory$file;
fi
if [ $c -eq 0 ]; then
echo $directory$file;
fi
fi
done
}
#check for required parameters
if [ ${#1} -gt 0 ]; then
cd $1
echo "In Directory : `pwd`"
domywork
recursive "$1"
echo "$directory_count directories processed."
else
#print usage information
usage
fi
相关阅读 更多 +