命令格式如下:
SCRIPT_NAME SEARCH_ON_DIR SEARCH_FILENAME
1 #!/bin/bash 2 Find(){ 3 echo $3" "$1 4 files=`ls $1` 5 for file in $files 6 do 7 if [ -d $1"/"$file ] 8 then 9 Find $1"/"$file $2 `expr $3 + 1` 10 elif [ $file=$2 ] 11 then 12 echo $1"/"$2 13 fi 14 done 15 } 16 FindFile(){ 17 if [ -d $1 ] 18 then 19 Find $1 $2 0 20 else 21 echo "This is not a directory or does not exist" 22 fi 23 } 24 echo "Start finding $2 in $1" 25 FindFile $1 $2
基本实现简单查找功能,编写代码时应格外注意语法格式