首页 > 编程开发 > Shell > 正文  
Shell 递归程序设计-目录列表
出自:http://ehnt.net/clansoft/gb/ 2002年02月05日 15:03
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)

】【http://www.trainlinux.com】【Close
『相关资料』
设置Unix启动密码 (2002-02-05 15:03)
Shell 递归程序设计-批量转换大写文件名为小写 (2002-02-05 15:02)
shell实现Unix进程间信息交换的几种方法 (2002-02-04 15:02)
介绍B-SHELL的一些运用方法 (2002-02-04 15:02)
Home 

诚恩Linux培训工作室