#!/bin/bash #function name "readfile" readfile () { #function begins here #declare variables DIR=/home/jeipi/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 eval TTY$a=`cat $DIR* | grep "$a tty $a" |wc -l` eval echo "\$$TTY$a"# done Ttotal=$((TTY1+TTY2+TTY3)) echo $Ttotal #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