Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm using a
diff
operation to check a couple of files, but am wondering if I can simultaneiously use it to trigger an event (e.g.
echo
-ing a line to terminal etc) without having to 'manually' check for the existence of the output report.
I had thought about using the report creation as a trigger, but as far as I know the file would be created regardless, it would just be empty in the event of no differences?
Basically, is it possible to have
diff
output a file, whilst inside an
if
statement, to keep my bash profile and the script itself as tidy as possible?
(If it helps, this is a follow on question to the wonderful help I received in this question:
Notifications on next ssh login
)
e.g. something to this effect?:
if [ diff filex filey > report.txt == true ]
# So the report.txt is created but the 'state' of
# the diff query is preserved and evaluated...
then echo "Files are different"
break
Hope that makes sense.
This is in Ubuntu bash FYI.
–
–
Yes, diff
exits with a status of 0 if there is no diffs (that's shell for "true"), so you can do it like this:
if ! diff <file1> <file2>
do the thing when there are diffs
do the thing when all is same
This should work even if you redirect the output.