home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!sgigate!rutgers!jvnc.net!darwin.sura.net!mips!sdd.hp.com!uakari.primate.wisc.edu!ames!bionet!ucselx!gdwest!good
- From: good@gdwest.gd.com (David L. Good)
- Newsgroups: comp.sys.hp
- Subject: Re: diff to return a value in a shell script?
- Message-ID: <1992Aug17.204604.23516@gdwest.gd.com>
- Date: 17 Aug 92 20:46:04 GMT
- References: <yy9mlkb.kc@netcom.com>
- Organization: General Dynamics Corp.
- Lines: 31
-
- In article <yy9mlkb.kc@netcom.com> kc@netcom.com (Dameon D. Welch) writes:
- >I'm writing a shell script under HP/UX 8.07 that will preform its task
- >if and only if any changes were made to the file. I need to have diff
- >somehow return only an integer value or some other method of determining
- >an error, no differences, or that there are diffs. I've read the man
- >page on diff and it does not specify an option to get what I want.
- >
- >Any ideas?
-
- Well, some simple experimentation reveals that diff has a return code 0 for
- no diffs, 1 for diffs, and 2 for errors, very similar to a number of other
- Unix commands.
-
- So...something like this should work:
-
- diff file oldfile >/dev/null 2>&1
- status=$?
-
- if [ $status eq 0 ] ; then
- exit 0;
- elif [ $status eq 1 ] ; then
- do_processing
- else
- process_errors
- fi
-
-
- --
- David Good good@gdwest.gd.com
-
- This space intentionally left blank.
-