error in the script

#!/bin/sh
diff C:\Janotech\bin\sample_file.log C:\Janotech\bin\sample_file.log.1 > C:\Janotech\bin\DIFFERENCE.log
cp C:\Janotech\bin\sample_file.log C:\Janotech\bin\sample_file.log.1
grep "ERROR" C:\Janotech\bin\DIFFERENCE.log
if [ $? -eq 0 ]; then
echo "1"
else
echo "0"
fi

I am trying to run this script but getting the following error.

./test3.sh[9]: [: -eq: unexpected operator/operand
0

Kindly suggest what missing in this

Regards

try this

if [[ "$?" -eq 0 ]]; then

$ ./test.sh
./test.sh[5]: syntax error: `"$?"' missing expression operator

Now it is giving this error

can any one help me in this please ??

#!/bin/sh
diff C:\Janotech\bin\sample_file.log C:\Janotech\bin\sample_file.log.1 > C:\Janotech\bin\DIFFERENCE.log
cp C:\Janotech\bin\sample_file.log C:\Janotech\bin\sample_file.log.1
grep "ERROR" C:\Janotech\bin\DIFFERENCE.log
if [ $? �eq 0 ]; then
echo "1"
else
echo "0"
fi

P.S.--- I have to search "ERROR" word in the DIFFERENCE.log and if its there 1 should be output otherwise 0.

Kindly reply

try adding debugging option at the top just before diff command so that you will see what your script does.

set -x

For this purpose grep has the -q or --silent option:

grep -q ERROR file && echo 1 || echo 0

HTH Chris