In a Unix shell script, I want to check if the output of a diff command is equal to 0 through an if statement. So that I can accordingly give the if case statements.
For example: Abc.sh
#!/bin/bash
cd users
diff s1 d1 > a.txt
wc -l a.txt | awk '{print f1}' > a
echo "value of a is"
cat a
if [ $a == 0 ]
then
echo "checksums match"
else
echo "checksums do not match"
fi
Output:
value of a is
0
[: ==: unary operator expected
checksums do not match
There are many ways to fix your script, but this is probably the most minimal:
a=$(cat a)
if [ "$a" = "" ]; then
(As suggested in the comment, if you don't need the diff
output, you could just use the exit code.)