#!/bin/bash #function name "readfile" readfile () { #function begins here #declare variables DIR=/home/chopseuy/bin/routeractivity/ra-logs/ #directory where logfiles are kept #if you want to specify the full path make sure #that you begin with "/" #also must always end in "/" LIMIT=3 #loop limit or number of tty to compare #loop begins here for ((a=1; a <= LIMIT ; a++)) # Double parentheses, and "LIMIT" with no "$". do TTY$a=`cat $DIR* | grep "$a tty $a" |wc -l` echo "tty $a = $TTY" done #function ends here } #close bracket for function close #check the logfiles first before running the script if [ -a "$DIR/" ] then readfile else echo "directory does not exist" fi