home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / hp / 9359 < prev    next >
Encoding:
Text File  |  1992-08-17  |  1.1 KB  |  41 lines

  1. Newsgroups: comp.sys.hp
  2. Path: sparky!uunet!mcsun!sunic!corax.udac.uu.se!irfu.se!jhd
  3. From: jhd@irfu.se (Jan D.)
  4. Subject: Re: diff to return a value in a shell script?
  5. Message-ID: <1992Aug17.200623.15886@irfu.se>
  6. Date: Mon, 17 Aug 1992 20:06:23 GMT
  7. References: <yy9mlkb.kc@netcom.com>
  8. Organization: Swedish Institute of Space Physics, Uppsala, Sweden
  9. Lines: 30
  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. Use cmp instead of diff. It's faster. For example:
  21.  
  22.     cmp -s $file1 $file2 2>/dev/null
  23.     status=$?
  24.  
  25.     if test X"$status" = X0
  26.     then
  27.         echo "Files $file1 and $file2 are identical"
  28.     fi
  29.     if test X"$status" = X1
  30.     then
  31.         echo "Files $file1 and $file2 differ"
  32.     fi
  33.     if test X"$status" = X2
  34.     then
  35.         echo "Error in arguments"
  36.     fi
  37.  
  38.  
  39.     Jan D.
  40.  
  41.