home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / hp / 9361 < prev    next >
Encoding:
Internet Message Format  |  1992-08-17  |  1.3 KB

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