How to pause a while loop while reading from a file

Hi,
I am building a script to grep for a string in all the files from a folder and display the results.
I am reading the files one by one by placing the names in other file using while loop
my code is as below

     while read inp
     do
          chk=`grep -c "$str" $pth/$inp`
          if [ $chk -ge 1 ]; then
               tot=`expr $tot + $chk`
               mwl=`expr $mwl + 1`
               pg=`expr $pg + $chk`
               tput bold
              echo " \n $inp        --------- STRING(S) FOUND ----------- \n "
               tput sgr0
               grep -n "$str" $pth/$inp
          else
               mwol=`expr $mwol + 1`
          fi
     done<tmp

but the results are scrolled down when i run the script, i want to pause the loop for a key stroke before going to second page based on number of lines printed captured in the variable "pg".

Unix gurus please help me in this regard.

Thanks and regards,
Somasekhar Gajjala.

If you want to see all the output generated by your script,you use the following command.

sh scriptname |less 

You can either call your script in a pipeline with some formatting command ('more' or 'pg' are the standard commands for this, 'less' will work the same if it is installed), as vivekraj already mentioned.

You could also "build in" this mechanism into your script:

...
while .... ; do
     ...
     <some long output generated here>
     .....
done | more

Still, it is more "unixish" to use the former and not this method, as it will be more versatile: suppose you would want to work on the output with yet another script you could do that with the former method by exchanging "more" with some other program, say some "script2.sh". This would not be possible if you incorporate the "more" into your script.

I hope this helps.

bakunin