1:遞歸樹形展現目錄spa
1 ShowTab() 2 { 3 whitespace="" 4 if [ $# -gt 0 ] && [ $1 -gt 0 ]; then 5 for index in $(seq 1 $1) 6 do 7 whitespace="${whitespace} " 8 done 9 fi 10 echo "${whitespace}" 11 } 12 13 ShowDir() 14 { 15 #if [ $# == 0 ]; then 16 # echo "no argument,exit!" 17 #elif [ ! -e $1 ]; then 18 # echo "filepath $1 is invalid" 19 if [ -d $1 ]; then 20 echo "$(ShowTab $2)$1" 21 argLs=$(ls $1) 22 for filename in ${argLs} 23 do 24 ShowDir $1/${filename} $(($2+1)) 25 done 26 elif [ -f $1 ]; then 27 echo "$(ShowTab $2)$1" 28 fi 29 } 30 31 paramOne="" 32 if [ $# == 0 ] ; then 33 paramOne=$(pwd) 34 else 35 paramOne=$1 36 fi 37 38 if [ ! -e ${paramOne} ]; then 39 echo "arg1: ${paramOne} is not exist" 40 exit 0 41 fi 42 43 ShowDir ${paramOne} 0
效果圖: code