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

  1. Path: sparky!uunet!cis.ohio-state.edu!rutgers!psinntp!psinntp!eye!paul
  2. From: paul@eye.com (Paul B. Booth)
  3. Newsgroups: comp.sys.hp
  4. Subject: Re: diff to return a value in a shell script?
  5. Message-ID: <1992Aug18.103014.28623@eye.com>
  6. Date: 18 Aug 92 14:30:14 GMT
  7. References: <yy9mlkb.kc@netcom.com>
  8. Organization: 3D/EYE, Inc.  Ithaca, NY
  9. Lines: 29
  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. Options, we don't need no stinkin' options....  The return codes from diff tell
  21. you exactly what you need to know.  I believe they're listed in the man page.
  22. Try something along these lines:
  23.  
  24.     diff file1 file2 >/dev/null 2>&1  # run diff and bit-bucket the output
  25.     case $? in                        # diff's return code is in $?
  26.     0)  echo "same"
  27.         ;;
  28.     1)  echo "different"
  29.         ;;
  30.     *)  echo "error"
  31.         ;;
  32.     esac
  33.  
  34. Regards-
  35. -- 
  36. Paul B. Booth  (paul@eye.com)
  37. -------------------------------------------------------------------------------
  38. 3D/EYE, Inc., 2359 N. Triphammer Rd., Ithaca, NY  14850    voice: (607)257-1381
  39.                                                              fax: (607)257-7335
  40.