Binary or ascii file

I want to verify the file is Binary or ascii file and accordingly I want to switch the program with ret code
ie 0 or success and 1 for failure
Can any one help me is this a correct syntex...i am getting error

#!/bin/ksh
$file filename
if [ $? -eq 'ascii' ]
   echo "ascii fie Found"
else
   echo " binary file not Found"
fi 

from the man page of find:

EXAMPLES
     Example 1: Binary executable files
     Determine if an argument is a binary executable file:

     file "$1" | grep -Fq executable &&
               printf "%s is executable.\n" "$1"

I want to get a condition how to verify the file is ascii or binary...I need to

I want to get a condition how to verify the file is ascii or binary...I need to create a condition if ascii then OK otherwise fail

could you please tell me what adject line should be put in syntax...should be eq to ascii ..

just an example only.

file "$1" | grep -Fq executable
if [ $? -eq 0 ];then
   echo "File is binary"
else
    file "$1" |egrep "ascii|text"
    if [ $? -eq 0 ];then
        echo "File is ascii"   
    fi
fi

With this script you can check value of ftype and based on that perform further actions.ftype will be 0 if file is ascii, 1 if executable otherwise 2.

ftype=2
file "$1" | grep -Fq ascii && ftype=0
file "$1" | grep -Fq executable && ftype=1
echo $ftype

if above script throw error for grep -F and -q option try below code.

ftype=2
file "$1" | /usr/xpg4/bin/grep -Fq ascii && ftype=0
file "$1" |/usr/xpg4/bin/grep -Fq executable && ftype=1
echo $ftype

use the below command to find the binary mode files.

filetype=`tac filename | sed -n '/^/{p;q;}'

Hope it will be working fine.

Francis A Vij