Going through your code line by line
Code:
#!/bin/ksh -x
#$1 - name of option
#$2 - pattern of filename or age of file
no problems so far
Code:
optn=`echo "$1"| tr "[A-Z]" "[a-z]"`
You've set 'optn' to $1 translated to lower case, but thenyou never use this. However you then test $1 against 'name' I assume you want to test $1, translated to lower case against 'name'
# so
Code:
if [ "$1" == "name" ]; then
should be
Code:
if [ "$optn" == "name" ]; then
Well, er, '$2', because of the single quotes, is uninterpreted, and you want optn to be '-name *.log' so try
Note the escaped double quotes
Code:
else
optn="-mtime +$2"
fi
Not to much wrong here. You haven't checked that $2 is numeric but we'll live with that.
Finally
Whilst this produces the right command, for some reason it doesnt seem to work. I resolved this by changing
to
Code:
optn="find . -type f -name \"$2\" -ls"
and the final line to
Putting it all together you get
Code:
#!/bin/ksh -x
#$1 - name of option
#$2 - pattern of filename or age of file
optn=`echo $1 | tr "[A-Z]" "[a-z]"`
if [ "$optn" = "name" ]
then
optn="find . -type f -name \"$2\" -ls"
else
optn="find . -type f -mtime +$2"
fi
ksh -c "$optn"
Which works for me.
Ceci n'est pas une signature
Columb Healy