![]() |
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 |
Homework?
|
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. |
Quote:
Any pointers? |
|
Quote:
|
| All times are GMT -5. The time now is 05:56 AM. |