Chinaunix首页 | 论坛 | 博客
  • 博客访问: 90343129
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类:

2008-05-10 13:25:50

??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)
阅读(595) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~