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