I have to compare a file with 3 different golden files using diff.
I need to exit the script with exit 0 if test file is the same as any of the three golden files.
I tried the following:
#!/bin/sh
one=`diff -q NEW_GOLDEN_OUTPUT_ASYNC_1 /tmp/tmp_last_lines.log`
two=`diff -q NEW_GOLDEN_OUTPUT_ASYNC_2 /tmp/tmp_last_lines.log`
three=`diff -q NEW_GOLDEN_OUTPUT_ASYNC_3 /tmp/tmp_last_lines.log`
if [[ $one || $two || $three ]]; then
exit 0
else
exit 1
fi
But it returns exit 0 in all cases. I’m using /bin/ksh shell. Any suggestions?
Your code looks at the output of
diffbut you should look at the exit code. Try this instead:&&will only execute the next command if the previous one succeeded.Alternatively, use
set -e(Exit immediately if a command exits with a non-zero status.):