1

I have some commands in a file that are like

diff file1 file2
diff file3 file4

And if anything is output I want to print which command this happened in such as

diff file1 file2
if (there was output from the diff command)
     print "file1 and file2 had the difference"
endif
diff file3 file4
if (there was output from the diff command)
     print "file3 and file4 had the difference"
endif

1 Answer 1

3

The diff command exits with 1 if there is a difference. The easy way uses that as a success/failure check:

diff file1 file2 || print "file1 and file2 had the difference"
diff file3 file4 || print "file3 and file4 had the difference"

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.