1 1.1 mrg #!/bin/sh 2 1.1 mrg # Like mv $1 $2, but if the files are the same, just delete $1. 3 1.1 mrg # Status is zero if successful, nonzero otherwise. 4 1.1 mrg 5 1.5 mrg VERSION='2012-01-06 07:23'; # UTC 6 1.3 mrg # The definition above must lie within the first 8 lines in order 7 1.3 mrg # for the Emacs time-stamp write hook (at end) to update it. 8 1.3 mrg # If you change this file with Emacs, please let the write hook 9 1.3 mrg # do its job. Otherwise, update this string manually. 10 1.1 mrg 11 1.5 mrg # Copyright (C) 2002-2014 Free Software Foundation, Inc. 12 1.1 mrg 13 1.3 mrg # This program is free software: you can redistribute it and/or modify 14 1.3 mrg # it under the terms of the GNU General Public License as published by 15 1.3 mrg # the Free Software Foundation, either version 3 of the License, or 16 1.3 mrg # (at your option) any later version. 17 1.3 mrg 18 1.3 mrg # This program is distributed in the hope that it will be useful, 19 1.3 mrg # but WITHOUT ANY WARRANTY; without even the implied warranty of 20 1.3 mrg # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 1.3 mrg # GNU General Public License for more details. 22 1.3 mrg 23 1.3 mrg # You should have received a copy of the GNU General Public License 24 1.3 mrg # along with this program. If not, see <http://www.gnu.org/licenses/>. 25 1.3 mrg 26 1.3 mrg usage="usage: $0 SOURCE DEST" 27 1.3 mrg 28 1.3 mrg help="$usage 29 1.3 mrg or: $0 OPTION 30 1.3 mrg If SOURCE is different than DEST, then move it to DEST; else remove SOURCE. 31 1.3 mrg 32 1.3 mrg --help display this help and exit 33 1.3 mrg --version output version information and exit 34 1.3 mrg 35 1.5 mrg The variable CMPPROG can be used to specify an alternative to 'cmp'. 36 1.3 mrg 37 1.3 mrg Report bugs to <bug-gnulib (at] gnu.org>." 38 1.3 mrg 39 1.3 mrg version=`expr "$VERSION" : '\([^ ]*\)'` 40 1.3 mrg version="move-if-change (gnulib) $version 41 1.3 mrg Copyright (C) 2011 Free Software Foundation, Inc. 42 1.3 mrg License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 43 1.3 mrg This is free software: you are free to change and redistribute it. 44 1.3 mrg There is NO WARRANTY, to the extent permitted by law." 45 1.3 mrg 46 1.3 mrg cmpprog=${CMPPROG-cmp} 47 1.3 mrg 48 1.3 mrg for arg 49 1.3 mrg do 50 1.1 mrg case $arg in 51 1.3 mrg --help | --hel | --he | --h) 52 1.3 mrg exec echo "$help" ;; 53 1.3 mrg --version | --versio | --versi | --vers | --ver | --ve | --v) 54 1.3 mrg exec echo "$version" ;; 55 1.3 mrg --) 56 1.3 mrg shift 57 1.3 mrg break ;; 58 1.3 mrg -*) 59 1.3 mrg echo "$0: invalid option: $arg" >&2 60 1.3 mrg exit 1 ;; 61 1.3 mrg *) 62 1.3 mrg break ;; 63 1.1 mrg esac 64 1.1 mrg done 65 1.1 mrg 66 1.3 mrg test $# -eq 2 || { echo "$0: $usage" >&2; exit 1; } 67 1.3 mrg 68 1.3 mrg if test -r "$2" && $cmpprog -- "$1" "$2" >/dev/null; then 69 1.3 mrg rm -f -- "$1" 70 1.1 mrg else 71 1.3 mrg if mv -f -- "$1" "$2"; then :; else 72 1.3 mrg # Ignore failure due to a concurrent move-if-change. 73 1.3 mrg test -r "$2" && $cmpprog -- "$1" "$2" >/dev/null && rm -f -- "$1" 74 1.3 mrg fi 75 1.1 mrg fi 76 1.3 mrg 77 1.3 mrg ## Local Variables: 78 1.3 mrg ## eval: (add-hook 'write-file-hooks 'time-stamp) 79 1.3 mrg ## time-stamp-start: "VERSION='" 80 1.3 mrg ## time-stamp-format: "%:y-%02m-%02d %02H:%02M" 81 1.3 mrg ## time-stamp-time-zone: "UTC" 82 1.3 mrg ## time-stamp-end: "'; # UTC" 83 1.3 mrg ## End: 84