views:

63

answers:

1

I am trying to analyze the files/directories inside of a directory using a shell script, for example if the file is readable, if it is a file, if it is a directory, etc. My script is set up to take a directory as input. so I would type 'file.sh directoryname'. However, when I create a for loop to analyze the files, it analyzes the files in my current working directory rather than the specified directory name.

This is my broken code:

file=$1
set mypath = $file
for file in $mypath *
do

if [ -d $file ]
  dirCount=`expr $dirCount + 1`
fi

done

Why does this read the working directory instead of the specified directory? Any help is appreciated. Thanks

A: 

I think you have an error here:

set mypath = $file

Just do

mypath = $file

and that should work out just fine.

Jon