Jeff Abrahamson on 19 Feb 2006 20:51:10 -0000 |
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 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
|
|