Find Directory help

Hey All,

New to Bash Scripting I have a find command to count the current directories it is:

dirCount=`find $2/ -type d | wc -l`

What I get is a count of all directories in $2 as well as $2 itself.

What I need to do is ignore $2 itself and just get the folders inside $2.

Thank in advanced any help is appreciated.

Try a cd $2

 cd $2
find . -type d| wc -l

You will get the same correct result. Why? -- because when you cd to $2 - meaning that your current working directory is "$2" - Then there is a directory named "." That is how $2 is represented when are "inside" the directory.

If that offends you simply subtract 1 from the result.

Sadly this is not working still giving me a count including $2 I can't subtract 1 from the result as it does not pass the check.

Here..

find $2/* -type d  | wc -l

:S that got me 0 22

it should be 9 22

What do you mean by 9 22 and 0 22.
considering $2 is a directory name. As per your previous text you were worried about count being 1+ than total number of directories inside given dir. see example below.

$ find tmp/ -type d 
tmp/
tmp/HL_new
tmp/pdfcrack-0.11
tmp/perl
tmp/perl/maya
tmp/perl/test

$ find tmp/ -type d | wc -l
6


$ find tmp/* -type d 
tmp/HL_new
tmp/pdfcrack-0.11
tmp/perl
tmp/perl/maya
tmp/perl/test

$ find tmp/* -type d | wc -l
5

May be something else can be done if u paste ur sample dir structure/output.

This is not making sense. Of course you can subtract. (bash or ksh)

#!/bin/ksh
dirCount=$((  $(find $2/ -type d | wc -l`) - 1 ))

There is something very inportant you are not telling us. Please show your code.

This is starting to sound like homework. We have a special homework forum.