Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->Linux技术 ->Linux程序设计 ->正文

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

来源:Linuxdby.com 作者:Webmaster 时间:2007-06-04 点击: [收藏] [投稿]
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)



 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:Linux程式设计-11.ShellScript(bash)--(18)语法   下一篇:设置Unix启动admin888

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号