查看完整版本: 如何用 Shell 脚本编写递归程序

lcs200725 2007-10-19 16:32

如何用 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 "${PWD}/$d"

[ -d "$d" -a -x "$d" ]
页: [1]

查看完整版本: 如何用 Shell 脚本编写递归程序