Ich habe einige Befehle in einer Datei, die wie folgt lauten:
diff file1 file2
diff file3 file4
Und wenn etwas ausgegeben wird, möchte ich ausdrucken, in welchem Befehl dies passiert ist, beispielsweise
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
Antwort1
Der Diff-Befehl wird beendet, 1
wenn ein Unterschied besteht. Der einfache Weg verwendet dies als Erfolg/Misserfolg-Prüfung:
diff file1 file2 || print "file1 and file2 had the difference"
diff file3 file4 || print "file3 and file4 had the difference"