当前位置:首页>网络学院>程序开发>shell教程>文章内容

Shell递归程序设计-目录列表

[ 来源: | 作者: | 时间:2007-07-17 | 收藏 | 推荐 ] 【

UNIXShell脚本类似DOS的批处理命令,但比较起来UNIXShell的功能更强大,在某些方面,Shell甚至超过了一些高级语言。
下边的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)
www.it55.com

(编辑:IT资讯之家 www.it55.com

返回顶部
 

网友评论

[以下评论为网友观点,不代表本站。请自觉遵守互联网相关政策法规,所有连带责任均有评论者自负。]
[不超过250字]

图片文章