У меня есть несколько команд в файле, которые выглядят так:
diff file1 file2
diff file3 file4
И если что-то выводится, я хочу вывести, в какой команде это произошло, например
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
Команда diff завершается с , 1
если есть разница. Простой способ использует это как проверку успеха/неудачи:
diff file1 file2 || print "file1 and file2 had the difference"
diff file3 file4 || print "file3 and file4 had the difference"