Shell递归程序设计-目录列表
时间:2008-05-10 来源:sdccf
iTbulo.COM |
??下边的Shell脚本演示了如何用Shell脚本编写递归程序。 ??运行前先执行下述准备命令: ??lntree.sh/usr/bin/tree ??lntree.sh/usr/bin/wtree ??lntree.sh/usr/bin/dtree ??rmtree.sh #tree.sh #DepthfirstDirectorylist dtree(){ PWD=`pwd|sed's/\/\$//` fordin$* do echo"${PWD}/$d" [-d"$d"-a-x"$d"]&&{ cd"$d" dtree* cd.. PWD=`pwd|sed's/\/\$//`#restorePWD } done } #DepthfirstDirectorylist wtree(){ PWD=`pwd|sed's/\/\$//` fordin$* do echo${PWD}/$d done fordin$* do [-d"$d"-a-x"$d"]&&{ cd$d wtree* cd.. } done } #Directorylist tree(){ PWD=`pwd|sed's/\/\$//` fordin$* do echo${PWD}/$d done } #main TREE=`basename$0` if["$1"] thenDIR="$1" elseDIR="." fi ifcd$DIR then$TREE* elseecho"$0:Directory$1readfail." fi #(End) |
相关阅读 更多 +