home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / conf / cmpto < prev    next >
Text File  |  1994-09-15  |  979b  |  53 lines

  1. #! /bin/sh
  2. # compare files to those in a directory
  3. # -i means don't get upset about mismatches
  4. # -e means strip .eg suffix off filenames
  5. # -x means don't get upset if the file doesn't exist, but do if mismatch
  6. ignore=n
  7. strip=n
  8. mustexist=y
  9. for dummy
  10. do
  11.     case "$1" in
  12.     -i)    ignore=y    ;;
  13.     -e)    strip=y        ;;
  14.     -x)    mustexist=n    ;;
  15.     --)    shift ; break    ;;
  16.     -*)    echo "$0: unknown option \`$1'" >&2 ; exit 2    ;;
  17.     *)    break        ;;
  18.     esac
  19.     shift
  20. done
  21. case "$#" in
  22. 0|1)    echo "Usage: $0 [-i] dir file ..." >&2 ; exit 2    ;;
  23. esac
  24.  
  25. dest="$1"
  26. shift
  27. if test ! -d "$dest"
  28. then
  29.     echo "$0: directory \`$dest' does not exist" >&2
  30.     exit 1
  31. fi
  32.  
  33. status=0
  34. for f
  35. do
  36.     case "$f" in
  37.     */*)    echo "$0: can't handle / in \`$f'" >&2 ; exit 1    ;;
  38.     esac
  39.     case "$strip:$f" in
  40.     y:*.eg)    d="$dest/`expr $f : '\(.*\)\.eg'`"    ;;
  41.     *)    d="$dest/$f"                ;;
  42.     esac
  43.     if test -f $d
  44.     then
  45.         cmp $f $d || test " $ignore" = " y" || status=1
  46.     elif test " $mustexist" = " y"
  47.     then
  48.         echo "$0: \`$d' does not exist!" >&2
  49.         status=1
  50.     fi
  51. done
  52. exit $status
  53.