Question : Problem with file name comparison in unix script

Hello,
Can you help me in updating my script? I have script named rite.sh in /xyz directory. There are some other files in same directory like abc_out.txt_999999, asd.txt_8878773. These are the 2 types of files in the above said directory. I will run the script by passing a parameter like
./rite.sh /xyz/abc_out.txt_999999
The script should check the file name. If the parameter is abc_out* then it should copy to abc_out.txt file.
If the parameter is asd.txt_8878773 then it should copy to asd.txt file.
Here is my script:
#!/usr/bin/ksh
### Variables
set -x
FILE=$1
BASE=$( basename ${FILE} )
WORKDIR=$( dirname ${FILE} )

### change into working directory
cd ${WORKDIR}
if [[ $? != 0 ]]
then
echo "cannot cd into ${WORKDIR}"
exit 1
fi
###
VARFILE=$( basename ${FILE} )
if [[ ${VARFILE} = "abc_out.txt*" ]]
then
FIXFILE="abc_out.txt"
cp ${VARFILE} ${FIXFILE}
else
FIXFILE="asd.txt"
cp ${VARFILE} ${FIXFILE}
fi
fi
exit 0

Here the file abc_out.txt_999999 is copied to asd.txt. But I want it to copy in abc_out.txt. Is there any problem in comparing file name. Can you please help me out where I went wrong?

Thanks,
MSK

Answer : Problem with file name comparison in unix script

Here you go
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
#!/bin/ksh
if [ $# -ne 1 ]
then
   echo "Usage $0 [filename]"
   exit 1
fi

FILE=$1

if [ ! -f $FILE ]
then
   echo "$FILE does not exist"
   exit 1
fi

cp $FILE ${FILE%_*}
Random Solutions  
 
programming4us programming4us