Comparing files and capture return code

Hi,

I would like to compare 2 files, and have a return code write to a file.
regardless of the files contents are the same the code should be writing to a file (if both files contents are same then return code 0).
A simple example will be great :slight_smile:

Thanks

using echo $? .. you get status

Hi, I have below code:

vi test.sh

#!/bin/ksh
CHKTEST=`cd /tmp;ls test1.log> /dev/null 2>&1`
CHKTESTRESULT="test1.log"
[[ CHKTEST = CHKTESTRESULT ]]
echo $?

When i ran ./test.sh, I always completed with 1 although I have test1.log in /tmp.

Any advice will great appreciate.
Thanks

if you want to check the existence of the file. then you can try the below

 
[ -f /tmp/test1.log ] && echo "File exist" || echo "File not exist"
 
ls /tmp/test1.log> /dev/null 2>&1
[ "$?" -eq "0" ] && echo "File exist" || echo "File not exist"