Jeff Abrahamson on 19 Feb 2006 21:05:48 -0000 |
If one doesn't exist it returns 2. -Jeff On Sun, Feb 19, 2006 at 03:58:45PM -0500, Kyle R. Burton wrote: > [73 lines, 274 words, 1904 characters] Top characters: -en_\ntoa > > Can you just: > > if cmp -s "$f" "$dir2/b"; then > echo "same" > else > echo "not same" > fi > > ? > > If one doesn't exist, cmp will return 1 (false). If they both exist and are > the same, then it will return 0 (true). > > Kyle > > On 2/19/06, Jeff Abrahamson <jeff@purple.com> wrote: > > > > In a bash script I want to compare two files (one or both of which may > > not exist) and take a certain action if they *both* exist and are > > identical. > > > > Refresher, cmp returns 0 on equality, 1 on inequality, 2 on error such > > as one or both files doesn't exist. > > > > The following attempt fails miserably (at the syntax level, for > > obvious reasons): > > > > if [ (cmp -s "$f" "$dir2/$b") -a $? == 0 ]; then > > > > Anyone know how to combine a subshell invocation with a logical > > operation in an if clause? > > > > I'd like to be more elegant than a double if, merely on principle: > > > > if [ -r "$f" -a -r "$dir2/$b" ]; then > > if ( cmp -s ... ); then ... > > > > -- > > Jeff > > > > Jeff Abrahamson <http://www.purple.com/jeff/> +1 215/837-2287 > > GPG fingerprint: 1A1A BA95 D082 A558 A276 63C6 16BF 8C4C 0D1D AE4B > > > > > > -----BEGIN PGP SIGNATURE----- > > Version: GnuPG v1.4.2 (GNU/Linux) > > > > iD8DBQFD+NomFr+MTA0drksRAhD1AJ92LZeXi2wa+w7nNDgOSfM0f8q1tQCdEfMo > > e37rkpjAaV69vQdLY0wNPb8= > > =ungl > > -----END PGP SIGNATURE----- > > > > > > > > ___________________________________________________________________________ > > Philadelphia Linux Users Group -- > > http://www.phillylinux.org > > Announcements - > > http://lists.phillylinux.org/mailman/listinfo/plug-announce > > General Discussion -- > > http://lists.phillylinux.org/mailman/listinfo/plug > > > > > > > > > -- > ------------------------------------------------------------------------------ > Wisdom and Compassion are inseparable. > -- Christmas Humphreys > kyle.burton@gmail.com > http://www.neverlight.com/~mortis > ------------------------------------------------------------------------------ > [4 lines, 14 words, 304 characters] Top characters:_ linstpo > > ___________________________________________________________________________ > Philadelphia Linux Users Group -- http://www.phillylinux.org > Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce > General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug -- Jeff Jeff Abrahamson <http://www.purple.com/jeff/> +1 215/837-2287 GPG fingerprint: 1A1A BA95 D082 A558 A276 63C6 16BF 8C4C 0D1D AE4B Attachment:
signature.asc ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
|
|