實現思路就是深度優先搜索的實現思路,不過第一次在linux下寫腳本,還需要適應。比如if語句的中括號兩邊一定要留空格之類的。
function dfs{ local now_dir now_file now_dir=$1 for now_file in $(ls ${now_dir}) do if [ -f $now_file ] then echo $now_file fi done for now_file in $(ls ${now_dir}) do if [ -d $now_file ] then cd ${now_file} dfs ${now_dir}/${now_file} cd .. fi done}if [ -f $1 ]then echo "the input is a file"else dfs $1fi搜索結果如下:
新聞熱點
疑難解答