Reading into directory, unix shell script

Posted by dubya on Stack Overflow See other posts from Stack Overflow or by dubya
Published on 2010-04-23T23:56:34Z Indexed on 2010/04/24 0:03 UTC
Read the original article Hit count: 227

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

© Stack Overflow or respective owner

Related posts about unix

Related posts about shell-scripting