home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.hp
- Path: sparky!uunet!mcsun!sunic!corax.udac.uu.se!irfu.se!jhd
- From: jhd@irfu.se (Jan D.)
- Subject: Re: diff to return a value in a shell script?
- Message-ID: <1992Aug17.200623.15886@irfu.se>
- Date: Mon, 17 Aug 1992 20:06:23 GMT
- References: <yy9mlkb.kc@netcom.com>
- Organization: Swedish Institute of Space Physics, Uppsala, Sweden
- Lines: 30
-
- 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?
-
- Use cmp instead of diff. It's faster. For example:
-
- cmp -s $file1 $file2 2>/dev/null
- status=$?
-
- if test X"$status" = X0
- then
- echo "Files $file1 and $file2 are identical"
- fi
- if test X"$status" = X1
- then
- echo "Files $file1 and $file2 differ"
- fi
- if test X"$status" = X2
- then
- echo "Error in arguments"
- fi
-
-
- Jan D.
-
-