LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Trying to identify file types(command line arguments) and count how many there are (http://www.linuxquestions.org/questions/linux-newbie-8/trying-to-identify-file-types-command-line-arguments-and-count-how-many-there-are-790445/)

jdwalk 02-20-2010 03:38 PM

Trying to identify file types(command line arguments) and count how many there are
 
Write a script that will take a list of filenames as arguments and output a count of how many of them are regular files, and how many of them are scripts (if the file is executable, it will be assumed to be a script file)

counts always come back as 0

regCount=0
scriptCount=0
for arg in $@
do
if [ "$1" = "-f" ] # checks to see if a regular file
then
regCount+1 # adds to count
shift # shifts arguments
elif [ "$1" = "-x" ]
then
scriptCount+1 # adds to count
shift # shifts arguments
fi
done
echo Regular files: $regCount
echo Script files: $scriptCount

arochester 02-20-2010 04:05 PM

Homework?

mattca 02-20-2010 04:11 PM

Haha, yeah it does sound like a homework assignment.

But in any case you can find both totals with one line each, using ls and grep. And there are possibly even more elegant methods.

jdwalk 02-20-2010 04:20 PM

Quote:

Originally Posted by arochester (Post 3870817)
Homework?

Yes homewok

Any pointers?

whizje 02-20-2010 04:22 PM

Try
Code:

[ -f "$1" ]
http://tldp.org/LDP/abs/html/fto.html

jdwalk 02-20-2010 04:51 PM

Quote:

Originally Posted by whizje (Post 3870831)

That helped thanks


All times are GMT -5. The time now is 03:30 PM.