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