How to use Shell scripts to write recursive programs
Source: Internet
Author: User
Article Title: how to use Shell scripts to write recursive programs. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
The UNIX Shell script is similar to the DOS batch processing command, but it is more powerful than the UNIX Shell. in some respects, Shell is more than some advanced languages.
The Shell script below demonstrates how to use Shell scripts to write recursive programs.
Run the following preparation command before running:
?? 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"] & {
Cd "$ d"
Dtree *
Cd ..
PWD = 'pwd | sed's // \ $ // '# restore pwd
}
Done
}
# Depth first Directory list
Wtree (){
PWD = 'pwd | sed's/\ $ //'
For d in $ *
Do
Echo $ {PWD}/$ d
Done
For d in $ *
Do
[-D "$ d"-a-x "$ d"] & {
Cd $ d
Wtree *
Cd ..
}
Done
}
# Directory list
Tree (){
PWD = 'pwd | sed's/\ $ //'
For d in $ *
Do
Echo $ {PWD}/$ d
Done
}
# Main
TREE = 'basename $0'
If ["$1"]
Then DIR = "$1"
Else DIR = "."
Fi
If cd $ DIR
Then $ TREE *
Else echo "$0: Directory $1 read fail ."
Fi
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service