I have two files, say
I am executing the
diff command, ignoring the line endings. Command and code is as below:
diff --strip-trailing-cr file1 file2 > /dev/null if [ $? -eq 0 ]; then echo "no diff" elif if [ $? -eq 1 ]; then echo "there is diff" else echo "something is wrong" fi
When I execute this, if the
file2 contents are the same,
then I am getting result as "no diff" which is correct.
But the problem comes when the
file2 contents have some differences,.
In this case it is just executing the
diff command (as mentioned above) and printing the differences and exiting. It is not going to the if-else section at all.
I am running this code in a
for loop (not shown here)
as there are many files which I need to compare.
But my script exits as soon as it finds the first pair of files
with a diff by printing the difference
and it is not going to the if-else section at all.
Not sure what is wrong with it.
Any help would be highly appreciated
Result I am Expecting
When there is a diff between the files then it should not print the difference. Instead it should go to the section
elif if [ $? -eq 1 ]; then and print "there is diff", and then continue with the
for loop by comparing the other files.