Re: Directory level Depth check - Shell script
- From: Meendar <meendar@xxxxxxxxx>
- Date: Wed, 30 Jan 2008 20:48:48 -0800 (PST)
On Jan 31, 9:26 am, Logan Shaw <lshaw-use...@xxxxxxxxxxxxx> wrote:
Barry Margolin wrote:
In article
<4b83a38d-24ca-486b-999e-8f9977091...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Meendar <meen...@xxxxxxxxx> wrote:
Anybody know how to compare the directory depth level of twoCount the number of '/' characters in the pathnames and compare them.
directories, whether their depth level are same or not through shell
script. (also depth level for each sub-directory )
i have googled abt this, but couldn't find the prompt answer.
Of course, for this solution to work in all cases, you've got to
do some sort of canonicalization process first, since "foo/bar"
and "foo/bar/" and "foo/////bar" are all legal ways of referring
to the same directory. :-)
One other possible solution:
dir_depth() {
dir="$1"
depth=1
while [ X"$dir" != X"." -a X"$dir" != X"/" ]
do
dir=`dirname "$dir"`
depth=`expr "$depth" + 1`
done
echo "$depth"
}
It's a little ugly, but it mostly works.
There are some questions to be answered, though: for instance,
what is the depth of the pathname "foo/../foo/../foo/bar"?
- Logan
Thanks to All
.
- References:
- Directory level Depth check - Shell script
- From: Meendar
- Re: Directory level Depth check - Shell script
- From: Barry Margolin
- Re: Directory level Depth check - Shell script
- From: Logan Shaw
- Directory level Depth check - Shell script
- Prev by Date: Re: recv() vs recvfrom()
- Next by Date: equiv of .ppt slide
- Previous by thread: Re: Directory level Depth check - Shell script
- Next by thread: Re: Directory level Depth check - Shell script
- Index(es):
Relevant Pages
|
|