LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-20-2010, 03:38 PM   #1
jdwalk
LQ Newbie
 
Registered: Feb 2010
Posts: 9

Rep: Reputation: 0
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
 
Old 02-20-2010, 04:05 PM   #2
arochester
Member
 
Registered: May 2006
Location: Scotland
Distribution: Debian Squeeze Xfce
Posts: 569

Rep: Reputation: 79
Homework?
 
Old 02-20-2010, 04:11 PM   #3
mattca
Member
 
Registered: Jan 2009
Distribution: Slackware 14.1
Posts: 326

Rep: Reputation: 56
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.
 
Old 02-20-2010, 04:20 PM   #4
jdwalk
LQ Newbie
 
Registered: Feb 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by arochester View Post
Homework?
Yes homewok

Any pointers?
 
Old 02-20-2010, 04:22 PM   #5
whizje
Member
 
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 583

Rep: Reputation: 129Reputation: 129
Try
Code:
[ -f "$1" ]
http://tldp.org/LDP/abs/html/fto.html
 
Old 02-20-2010, 04:51 PM   #6
jdwalk
LQ Newbie
 
Registered: Feb 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by whizje View Post
That helped thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to write command line arguments as values, into a file which contains variables sathiawathi.m Linux - Newbie 2 07-17-2009 03:27 AM
Command line arguments bioinformatics_guy Linux - Newbie 2 02-12-2009 08:26 AM
need some help regarding command line arguments kristam269 Linux - General 1 01-23-2007 10:40 AM
Command line arguments?? almagerenia Linux - Newbie 1 09-08-2006 05:05 AM
Passing a text file to the command line as arguments wimnat Linux - General 2 12-05-2005 09:09 AM


All times are GMT -5. The time now is 02:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration