UNIXShell脚本类似DOS的批处理命令,但比较起来UNIXShell的功能更强大,在某些方面,Shell甚至超过了一些高级语言。下边的Shell脚本演示了如何用Shell脚本编写递归程序。运行前先执行下述准备命令:lntree.sh/usr/bin/treelntree.sh/usr/bin/wtreelntree.sh/usr/bin/dtreermtree.sh#tree.sh#DepthfirstDirectorylistdtree(){PWD=`pwd|sed's/\/\$//`fordin$*doecho"${PWD}/$d"[-d"$d"-a-x"$d"]&&{cd"$d"dtree*cd..PWD=`pwd|sed's/\/\$//`#restorePWD}done}#DepthfirstDirectorylistwtree(){PWD=`pwd|sed's/\/\$//`fordin$*doecho${PWD}/$ddonefordin$*do[-d"$d"-a-x"$d"]&&{cd$dwtree*cd..}done}#Directorylisttree(){PWD=`pwd|sed's/\/\$//`fordin$*doecho${PWD}/$ddone}#mainTREE=`basename$0`if["$1"]thenDIR="$1"elseDIR="."fiifcd$DIRthen$TREE*elseecho"$0:Directory$1readfail."fi#(End)