How to get Find command work with a variable passing "*" value?

Hi guy,

I have a problem to pass a variable containing '*' value to FIND command.
below is the script. It doesn't work by submit below command:

rmf.sh name '*.txt'
or
rmf.sh name *.txt

I've tried either optn="-name '$2'" or optn="-name $2"., and there is no luck.

### (script name = rmf.sh) 
 #!/bin/ksh -x
 #$1 - name of option
 #$2 - pattern of filename or age of file

if [ "$1" == "name" ]; then
    optn="-name '$2'"
else
    optn="-mtime +$2"
fi
find . -type f $optn -ls

Thanks in advance

EDIT---
Updated to take care of "*", here is the code and sample use of the script:

admin@unix1:/home/admin/scripts$./find1 name "*.txt"
./test1/a.txt
./a.txt
./b.txt
admin@unix1:/home/admin/scripts$cat find1
### (script name = rmf.sh)
 #!/bin/ksh -x
 #$1 - name of option
 #$2 - pattern of filename or age of file
tmp=`echo "$2" | sed 's/\"//'`
if [ "$1" == "name" ]; then
    optn="-name"
else
    optn="-mtime"
fi
find . -type f $optn "$tmp" -print

Regards,
Tayyab

pls read the Rules and dont' cross-post.

Threads merged!

Thanks Shereenmotor,

find . -type f $optn "$tmp" doesn't work for me.

find . -type f $optn "$2" works fine.

I expect that $optn can pass more combined options (ie. -name "*.txt" -mtime +300) to FIND command.

Yes you are right "$2" should work also, because I was under the impression that $2 will have the value "*.txt" ie with quotes and it can create problem, therefore I stored the value of $2 in tmp variable after removing any quotes, but in fact tmp is not required here at all, you can remove that.

I don't understand exactly what you are trying to do here with passing same parameters which you can pass directly to find in the same fashion? It is almost useless to write code for the same function which is already provided in the command, we can do many things with parameters and find command but can you pls explain what is your exact requirement and why you need it?

Regards,
Tayyab

To shereenmotor:

My idea is to create an utility in a shell script for the user removing their old files. The utility leads the user to select an option from the screen manu to remove the file based on the age of file, pattern of file name or both. So the use is able to enter the paramater values. In the script, a string of option for FIND command will be assembled and be passed to the command line. Thanks again.