Shell Scripting Help/Ideas?

I understand the code in the following may not be perfect, but I'll work that out. I'm more looking for ideas on how to do what I need more efficiently.

I have log files that are archived each day so today's log is called nmslog, yesterday's is nmslog.1.gz, 2 days ago nmslog.2.gz, etc. I want to make a script that allows me to specify how many days back I want to check including everyday between now and the specified day.

The only way I can think to do this is with if statements like:

#!/bin/bash

echo -n "How many days back would you like to check?"; read days
echo -n "What would you like to search on?"; read search

if [ "days" = "1" ]; then
grep nmslog $search; zgrep nmslog.1.gz $search
elif [ "days" = "2" ]; then
grep nmslog $search; zgrep nmslog.1.gz $search; zgrep nmslog.2.gz
fi

The problem is there are 30 days of log files so that would be a very long if i wanted to search everyday between today and 25 days ago.

Is there a better way to do this?

Thanks for any help you can provide.

Consider something like this:

echo -n " number of previous days " 
read days
let i=1
grep  "$search" nmslog 
if [[ $days -eq 0 ]] then
   exit
fi
while [[ $i -le  $days ]]
do
    zgrep "$search"  nmslog.$i.gz
    let i=$i+1
done
#!/bin/ksh

# to consider:
# validating the days variable (make sure it is a number, etc)
# validating the search variable (make sure it not null, etc)

echo "how many days      \c"
read days
echo "enter search string \c"
read search

while [ ${days} -ne 1 ]; do
        let days=days-1
        zgrep ${search} nmslog.${days}.gz
done
grep ${search} nmslog

You can try something like that (not tested) :

#!/bin/bash

echo -n "How many days back would you like to check?"; read days
echo -n "What would you like to search on?"; read search

logs=
for ((d=1; d<days; d++))
do
   logs="${logs} nmslog.${d}.gz"
done

grep  ${search} nmslog
[ -n "${logs}" ] && zgrep ${search} ${logs}

Jean-Pierre.

Hey, never got a chance to say thanks for the replies all. I'm not able to post from work..

Anyways, ended up using TinWalrus' solution as it was the first one i tried that listed the log information in chronological order.

Thanks again.