会员控制台 会员登陆 会员注册 最后更新 高级搜索 会员投稿 退出登陆
设为首页
收藏本站
留言给我
  首页 | 操作系统类 | 程序设计类 | 数据库类 | 应用服务类 | 网络及硬件类 | 其他技术 | GBunix论坛
操作系统类
程序设计类
数据库类
应用服务类
网络及硬件类
其他技术
Unix中文 / 程序设计类 / SHELL / Shell 递归程序设计-目录列表
Shell 递归程序设计-目录列表
2004-07-13       ehnt.net    点击:
Shell 递归程序设计-目录列表
UNIX Shell 脚本类似 DOS 的批处理命令,但比较起来 UNIX Shell 的功能更强大,在某些方面,Shell 甚至超过了一些高级语言。
下边的 Shell 脚本演示了如何用 Shell 脚本编写递归程序。

运行前先执行下述准备命令:
ln tree.sh /usr/bin/tree
ln tree.sh /usr/bin/wtree
ln tree.sh /usr/bin/dtree
rm tree.sh


# tree.sh

# Depth first Directory list
dtree() {
PWD=`pwd|sed 's//$//`
for d in
do
echo "/"
[ -d "" -a -x "" ] && {
cd ""
dtree *
cd ..
PWD=`pwd|sed 's//$//` # restore PWD
}
done
}

# Depth first Directory list
wtree() {
PWD=`pwd|sed 's//$//`
for d in
do
echo /
done
for d in
do
[ -d "" -a -x "" ] && {
cd
wtree *
cd ..
}
done
}

# Directory list
tree() {
PWD=`pwd|sed 's//$//`
for d in
do
echo /
done
}

# main
TREE=`basename /usr/local/publish/cgi-bin/publish/doc_publish.pl`
if [ "" ]
then DIR=""
else DIR="."
fi
if cd
then *
else echo "/usr/local/publish/cgi-bin/publish/doc_publish.pl: Directory read fail."
fi

# (End)

了解更多详情,参与讨论,请进入GBUNIX论坛

http://www.gbunix.com/bbs/index.php
责任编辑: trotter
发表评论 查看评论 加入收藏 Email给朋友 打印本文
给该文章评分
1 2 3 4 5 6 7 8 9 10
平均得分 0, 共 0 人评分
1 2 3 4 5 6 7 8 9 10
发表评论
标题:
内容:
声明:本站资讯均来自互联网,所有文章版权归原作者和出版者所有,如涉及版权问题,请来信告知!
Copyright © 2002-2004 GBunix.com. All rights reserved.